Jump to content
Sign in to follow this  
sshrum

Is this a bug: random(1,1,1) returning 0

Recommended Posts

sshrum

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'

 

Share this post


Link to post
Share on other sites
herewasplato

... 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 by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Bowmore

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

Share this post


Link to post
Share on other sites
sshrum

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 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'

 

Share this post


Link to post
Share on other sites
weaponx

Func Random2($min, $max)
If $min = $max Then Return $min
$result = Random($min, $max,1)
Return SetError(@ERROR,0,$result)
EndFunc

Share this post


Link to post
Share on other sites
sshrum

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'

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.