Jump to content

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


sshrum
 Share

Recommended Posts

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'

 

Link to comment
Share on other sites

... 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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'

 

Link to comment
Share on other sites

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'

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...