Sign in to follow this  
Followers 0
atouit

Random Variable

4 posts in this topic

Hi,

I'm trying to make a script wich uses a random variable, I want something like $"randomletter" wich will result in $a or $b or $c like that.

It isn't really working at the moment, if anyone knows how to do this, please help me.

example:

$random1 = CHR(Random(Asc("a"), Asc("z"), 1))
$1 = $+$random1

I have 26 variables, a till z, and I want to use one of the 26 randomly picked.

Thx,

Atouit

Share this post


Link to post
Share on other sites



Hi,

I'm trying to make a script wich uses a random variable, I want something like $"randomletter" wich will result in $a or $b or $c like that.

It isn't really working at the moment, if anyone knows how to do this, please help me.

example:

$random1 = CHR(Random(Asc("a"), Asc("z"), 1))
$1 = $+$random1

I have 26 variables, a till z, and I want to use one of the 26 randomly picked.

Thx,

Atouit

Hi,

have look at functions Assign () and Eval () in helpfile.

;-))

Stefan

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It would make much more sense to put the values in an array and just randomize the index used:

Global $aArray[26]
For $n = 0 to UBound($aArray) - 1
    $aArray[$n] = 65 + $n
Next

While 1
    $iIndex = Random(0, UBound($aArray) - 1, 1)
    If MsgBox(64+1, "Result", "$aArray[" & $iIndex & "] = " & @CRLF & _
            "Sesame Street was brought to today by:" & @CRLF & _
            "The number:  " & $aArray[$iIndex] & @CRLF & _
            "And the letter:  " & Chr($aArray[$iIndex])) <> 1 Then ExitLoop
WEnd

Assign()/Eval() tend to make very sloppy, hard to maintain code.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

isn't it much easier to just put everything in an array and generate a random number? then get the value at that index?

Share this post


Link to post
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
Sign in to follow this  
Followers 0