Jump to content

Random Variable


atouit
 Share

Recommended Posts

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

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

Link to comment
Share on other sites

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