sshrum Posted September 6, 2008 Posted September 6, 2008 This function works great until the min and max match. I'm using it like this $iNext = random(1,$aFiles[0],1) If there is only 1 entry, I'd assume that a random between 1 and 1 would return...well...1 Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot'
herewasplato Posted September 6, 2008 Posted September 6, 2008 See this thread...http://www.autoitscript.com/forum/index.php?showtopic=72806Min cannot equal Max [size="1"][font="Arial"].[u].[/u][/font][/size]
Kip Posted September 6, 2008 Posted September 6, 2008 (edited) And again,.. They never say thanks, or whatsoever. Edited September 6, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
sshrum Posted September 7, 2008 Author Posted September 7, 2008 3.2.10.0 always returns 1 3.2.11.1 always returns 0 Ok then...can we ask that a feature of the random function be that if given a range of 1,1 while requesting integers, that it return 1? I understand that with float values random will never hit the end values whenas integer call are inclusive. The reason I ask is that alot of us deal with arrays and sometimes the array will have 1 entry in it...granted I could code for and array of 1 but honestly...I feel a random # generator given a max and min of 1 should return one. just my 2 cents. Thanx Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot'
herewasplato Posted September 7, 2008 Posted September 7, 2008 (edited) ... Ok then...can we ask that a feature of the random function be that if given a range of 1,1 while requesting integers, that it return 1? ...You can ask, but given the rejection of the bug report - I kinda doubt it will go thru.Edit: I Googled a few other forums and opinions vary on allowing min to = max. Edited September 7, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size]
Bowmore Posted September 7, 2008 Posted September 7, 2008 If min = max then it is impossible for the return value to be random so returning 0 and setting @error to 1 is the correct way for the function to work. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
sshrum Posted September 8, 2008 Author Posted September 8, 2008 (edited) If min = max then it is impossible for the return value to be random so returning 0 and setting @error to 1 is the correct way for the function to work. Understood...but given that there may be a situation where (when working with arrays of varying sizes) one may pass a $array[0] of 1 to random()... It would just be nice if it would return 1. I'm already testing for $array[0]=0 before working on the array...now I have to test for $array[0]=1 before I send it to random. If $array[0] = 1 then return 1 else return random($array[0],1,1) endif Edited September 8, 2008 by sshrum Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot'
weaponx Posted September 8, 2008 Posted September 8, 2008 Func Random2($min, $max) If $min = $max Then Return $min $result = Random($min, $max,1) Return SetError(@ERROR,0,$result) EndFunc
sshrum Posted September 8, 2008 Author Posted September 8, 2008 (edited) hehe weaponx...see the post above yours. I editted it just as you were posting But thanx for the input Edited September 8, 2008 by sshrum Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot'
sshrum Posted September 8, 2008 Author Posted September 8, 2008 I actually think I'll do as weaponx described...create a new func in my personal UDF called _Random and just do like his sample shows... I know this is beating a dead horse but honestly, I think (1,1,1) should return 1 Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot'
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