mooboo Posted May 30, 2004 Share Posted May 30, 2004 I want to get a random number between 1 and 3. When I use this script...$ran = Random ( 1,3 )msgbox (0, "", "" & $ran & "")I ALWAYS get a long decimal number. How can I get it to be full numbers only? And how come I never had this problem before? Link to comment Share on other sites More sharing options...
mooboo Posted May 30, 2004 Author Share Posted May 30, 2004 (edited) Sorry... I figured it out... the script needs to look like this...$ran = Random ( 1,3 ) ;Get random number$ran2 = Round ($ran) ;Round number to wholemsgbox (0, "", "" & $ran & "") ;Output Edited May 30, 2004 by mooboo Link to comment Share on other sites More sharing options...
Developers Jos Posted May 30, 2004 Developers Share Posted May 30, 2004 (edited) think this is a better way: $ran = int(Random (0,3 )+1) msgbox (0, "", "" & $ran & "") Your code will generate a number between 1.00000 and 2.9999999 1 - 1.499999 is rounded to 1 1.5 - 2.499999 is rounded to 2 2.5 - 2.999999 is rounded to 3 so theres a higher likelyhood that the result is 2 .... ( if i understand it correctly ) EDIT: come to think about it .. this should also work properly: $ran = int(Random (1,4 )) Edited May 30, 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...
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