Valuater Posted June 3, 2008 Share Posted June 3, 2008 (edited) I would think this should return a "1" $Number = Random(1,1,1) MsgBox(0x0,"", $Number) but...not!!!...??? I am looping though an array and it gets down to $x being a 1.. $Number = Random(1,$x,1) then it errors by returning a "0" 8) v3.2.12.0 win xp sp3 Edited June 3, 2008 by Valuater Link to comment Share on other sites More sharing options...
Airwolf Posted June 3, 2008 Share Posted June 3, 2008 (edited) $Number = Random(1,1,1) MsgBox(0x0,"", $Number) This does return a 1... at least, it did for me. Are you sure the value of $x is 1 when you have the problem? Edited June 3, 2008 by Airwolf123 Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt Link to comment Share on other sites More sharing options...
herewasplato Posted June 3, 2008 Share Posted June 3, 2008 (edited) What version of AutoIt are your two using...I always get a 0 using Val's code using v3.2.12.0Edit: or this code...ConsoleWrite(@CR) For $i = 1 To 10 $Number = Random(1, 1, 1) ConsoleWrite($Number & @CR) Next ConsoleWrite(@CR) Edited June 3, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 What version of AutoIt are your two using... I always get a 0 using Val's code using v3.2.12.0 Edit: or this code...ConsoleWrite(@CR) For $i = 1 To 10 $Number = Random(1, 1, 1) ConsoleWrite($Number & @CR) Next ConsoleWrite(@CR)oÝ÷ Ûú®¢×+&mmæ¥Ûezj+z·©ëÖ÷¨~Ø^¦ºjëh×6For $x = 5 To 1 Step -1 $Number = Random(1, $x, 1) MsgBox(0x0, $x, $Number, 2) Next thx 8) Link to comment Share on other sites More sharing options...
herewasplato Posted June 3, 2008 Share Posted June 3, 2008 this might be a little more representative of the prob... For $x = 5 To 1 Step -1 $Number = Random(1, $x, 1) MsgBox(0x0, $x, $Number, 2) Next thx 8)I know that is like the code that you are having problems with but you only get Random(1, $x, 1) to be Random(1, 1, 1) one time in that code. I was going for a repetition of Random(1, 1, 1) I get zero 10 out of 10 times with my little loop :-( What version of AutoIt are you using Val? [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
nikink Posted June 3, 2008 Share Posted June 3, 2008 works fine for me with 3.2.10 How odd! Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 I see.... 3.2.12.0For $x = 5 To 1 Step -1 $Number = Random(1, $x, 1) ConsoleWrite( "x=" & $x & " Num=" & $Number & @CRLF) NextExample outputx=5 Num=2x=4 Num=3x=3 Num=3x=2 Num=2x=1 Num=08) Link to comment Share on other sites More sharing options...
herewasplato Posted June 3, 2008 Share Posted June 3, 2008 Yep - a 1000 1s using v3.2.10.0ConsoleWrite(@CR) For $i = 1 To 1000 $Number = Random(1, 1, 1) ConsoleWrite($Number & @CR) Next ConsoleWrite(@CR)...Hmmmmm [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
enaiman Posted June 3, 2008 Share Posted June 3, 2008 Weird, ConsoleWrite(@CR) For $i = 1 To 10 $Number = Random(1, 1, 1) ConsoleWrite($Number & @CR) Next ConsoleWrite(@CR) 3.2.10.0 always returns 1 3.2.11.1 always returns 0 (tested 1000) SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
herewasplato Posted June 3, 2008 Share Posted June 3, 2008 (edited) ...and a 1000 0s using v3.2.12.0Nothing in the changelog for Random() that I saw. Edit: Correction - the full changelog does show two "fixes" to Random:http://www.autoitscript.com/autoit3/docs/a...t_changelog.txt- Fixed: AutoIt crash in Random() when range exceeds 2^31.- Fixed: Random(Min,Max,1). Previously this would never actually return Max, so if Max was artificially incremented by one the script will now need to be changed. Edited June 3, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 (edited) this looks strange too .99 min but an an integer result will be returned... it should not be "0" here either..AFAIK For $x = 5 To 1 Step -1 $Number = Random(.99, $x, 1) ConsoleWrite( "x=" & $x & " Num=" & $Number & @CRLF) Next 8) Edited June 3, 2008 by Valuater Link to comment Share on other sites More sharing options...
therks Posted June 3, 2008 Share Posted June 3, 2008 This has been reported and rejected (no bug): http://svn.autoitscript.com/trac/ticket/296 My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 ...and a 1000 0s using v3.2.12.0Nothing in the changelog for Random() that I saw. Edit: Correction - the full changelog does show two "fixes" to Random:http://www.autoitscript.com/autoit3/docs/a...t_changelog.txt- Fixed: AutoIt crash in Random() when range exceeds 2^31.- Fixed: Random(Min,Max,1). Previously this would never actually return Max, so if Max was artificially incremented by one the script will now need to be changed.I remember seeing that before, it may have "created" another bug area...thx 8) Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 This has been reported and rejected (no bug): http://svn.autoitscript.com/trac/ticket/296Thanks Saunders....But what about thisFor $x = 5 To 1 Step -1 $Number = Random(.99, $x, 1) ConsoleWrite( "x=" & $x & " Num=" & $Number & @CRLF) Nextx=5 Num=3x=4 Num=3x=3 Num=3x=2 Num=0x=1 Num=1I dont think there should be a 0 in there???8) Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 Well..., I guess I can just do this Func _FreeText_Random($T_GUI) If Not IsArray($T_GUI) Then Return 0 If UBound($T_GUI) - 1 = 1 Then Return 1 $rand = Random(1, UBound($T_GUI) - 1, 1) Return $rand ; $T_GUI[$rand][0] EndFunc ;==>_FreeText_Random return 1 if there is only 1 left... lol thx guys 8) Link to comment Share on other sites More sharing options...
herewasplato Posted June 3, 2008 Share Posted June 3, 2008 x=5 Num=5 x=4 Num=1 x=3 Num=0 x=2 Num=1 x=1 Num=1 ??? [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Valuater Posted June 3, 2008 Author Share Posted June 3, 2008 x=5 Num=5x=4 Num=1x=3 Num=0x=2 Num=1x=1 Num=1???yea... thats kinda funny Random(.99, $x, 1)will return a zero Dunno!!...???8) Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 4, 2008 Share Posted June 4, 2008 yea... thats kinda funny Random(.99, $x, 1) will return a zero Dunno!!...??? 8) It sets @error = 1 also, indicating invalid parameters: For $x = 5 To 1 Step -1 ConsoleWrite(@LF & "Debug: $x = " & $x & @LF) For $y = 1 To 5 $n = Random(1, $x, 1) ConsoleWrite("Debug: $n = " & $n & " @error = " & @error & @LF) Next Next So it may be as intended and just needs a update to the help file description that Min cannot equal Max. This does the same: For $x = 5 To 2 Step -1 ConsoleWrite(@LF & "Debug: $x = " & $x & @LF) For $y = 1 To 5 $n = Random(2, $x, 1) ConsoleWrite("Debug: $n = " & $n & " @error = " & @error & @LF) Next Next 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...
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