atouit Posted November 6, 2009 Share Posted November 6, 2009 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 = $+$random1I 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 More sharing options...
99ojo Posted November 6, 2009 Share Posted November 6, 2009 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 More sharing options...
PsaltyDS Posted November 6, 2009 Share Posted November 6, 2009 (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 November 6, 2009 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 More sharing options...
cageman Posted November 6, 2009 Share Posted November 6, 2009 isn't it much easier to just put everything in an array and generate a random number? then get the value at that index? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now