Recommended Posts

Is there anyway to use _FileReadToArray on a txt file and then do a FOR statement that uses the lines read into the array in a random order..??

Share on other sites

#include <File.au3>

Dim $fleText = @ScriptDir & '\text.txt' _ReadRandom($fleText)

Func _ReadRandom($ioFile) Local$fleLines = _FileCountLines($ioFile) Local$arrFile, $rnd _FileReadToArray($ioFile, $arrFile) For$i = 0 To UBound($arrFile) - 1$rnd = Random($arrFile[1], UBound($arrFile) - 1)
ConsoleWrite($arrFile[$rnd] & @CRLF)
Next
EndFunc

That's a start.

Share on other sites

Is there anyway to use _FileReadToArray on a txt file and then do a FOR statement that uses the lines read into the array in a random order..??

Something like this (could be the same line more times)

$SELECT = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1) Dim$FILE[1]
_FileReadToArray($SELECT,$FILE)
If IsArray($FILE) For$INDEX = 1 To $FILE[0]$RANDOM = Random(1,$FILE[0],1) MsgBox(0,"",$FILE[$RANDOM]) Next EndIf or like this: #include <Array.au3> #include <File.au3>$SELECT = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1)
Dim $FILE[1] _FileReadToArray($SELECT,$FILE) _ArrayDisplay($FILE)
If IsArray($FILE) Then For$INDEX = 1 To $FILE[0]*3 _ArraySwap($FILE[Random(1,$FILE[0],1)],$FILE[Random(1,$FILE[0],1)]) Next _ArrayDisplay($FILE)
EndIf
Edited by Andreik

When the words fail... music speaks

Share on other sites

well what im trying to do is: I have a FOR statement running from a _FileReadToArray from a .txt file and for every line in that .txt file i am performing a few functions ..

but I need to have a variable in this FOR statement that randomly changes for each new line in the _FileReadToArray

and this random variable will be coming from another _FileReadToArray from a diff .txt file..

So if yer still with me on what i just described, then how would i code something like this..??

Share on other sites

Try coding it yourself.... the helpfile, is errr, very helpfull

Create an account

Register a new account