BlueScreen Posted February 25, 2004 Share Posted February 25, 2004 Hey Guys... Wanted to know if there is a way to perform randomization to single numbers. I'll explain. $Res=Random(1,100) This will perform a randomization between 1 to 100. What should I do in order to perform a randomization between 323, 560, 23, etc? 10x Link to comment Share on other sites More sharing options...
Developers Jos Posted February 25, 2004 Developers Share Posted February 25, 2004 (edited) You means randomly pick a value from your list? $i="323, 560, 23,40" $ir = StringSplit($i,",") msgbox(4096,"Predefined Random","Your number is:" & $ir[round(Random(.5,ubound($ir)-1)+.5)]) Edited February 25, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BlueScreen Posted February 25, 2004 Author Share Posted February 25, 2004 10x JdeB, What is this .5? Link to comment Share on other sites More sharing options...
Developers Jos Posted February 25, 2004 Developers Share Posted February 25, 2004 10x JdeB, What is this .5?Good that you ask... since I made a mistake in the logic...(see below update here how it works: - ubound($ir) returns 5 in this case so need to subtract 1 - Random(.5, 4 + .49)-> will result in a random number between .5 - 4.49 - the round function will round: 0.5 - 1.49 -> 1 1.5 - 2.49 -> 2 2.5 - 3.49 -> 3 3.5 - 4.49 -> 4 - so $ir[$rn] retruns one of the array values. Does that make sense ? $i="323, 560, 23,40" $ir = StringSplit($i,",") $rn = Random(.5,ubound($ir)-1 + .49) $rn = Round($rn) $rn = $ir[$rn] msgbox(4096,"Predefined Random","You number is:" & $rn) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BlueScreen Posted February 25, 2004 Author Share Posted February 25, 2004 Great! That's exactly what I needed! 10x again JdeB Link to comment Share on other sites More sharing options...
Nutster Posted February 25, 2004 Share Posted February 25, 2004 (edited) It is easier on the user and the system to use Int.$i="323, 560, 23,40" $ir = StringSplit($i,",");$ir[0] contains the number of strings extracted. ; Argument of Random is the number of values to choose from. (4) ; The 1 being added is the starting valid value. $rn = Int(Random($ir[0]))+1 $rn = $ir[$rn] MsgBox(4096, "Predefined Random", "You number is:" & $rn)This is my prefered method of using Random; from the guy who wrote the random function. Yeah, there is a bug in the two-argument version for Random , but the 1 and 0 argument versions are working fine. Edit: I spoke (wrote?) too soon. Jon has installed the fix for Random in the current unstable version. Thanks, Jon. Edited February 25, 2004 by Nutster David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd... Link to comment Share on other sites More sharing options...
Developers Jos Posted February 25, 2004 Developers Share Posted February 25, 2004 (edited) It is easier on the user and the system to use Int. $rn = Int(Random($ir[0]))+1 good to know this also works ..... make it easier to code.. Edited February 25, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
CyberSlug Posted February 25, 2004 Share Posted February 25, 2004 What is the final word on what the docs should say? Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! 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