Jump to content

_FileReadToArray & Random Variables..?


Recommended Posts

#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.

Link to comment
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.

Link to comment
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..??

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...