HP Forums

Full Version: RANDINT parameters
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What is the expected behavior of RANDINT? According to Help, RANDINT(r,a,b) returns a list of size r which each element being a random integer from a to b.

However, the returned list may include a if a is greater than or equal to 0, but it will not include a if a is less than 0.

For example:
RANDINT(5,-1,1) returns {0,1,0,1,1} (but never a -1 in that list)
RANDINT(5,-2,1) returns {-1,-1,1,1,-1}
RANDINT(5,0,1} returns {1,0,1,1,1}

Furthermore, while Help on RANDINT(r,a,b) seems to imply that a is less than b,
the prime accepts inputs like RANDINT(r,5,-5). I am not sure how to interpret the output.

Any help? Thank you.
The order of the 2nd and 3rd arguments doesn't matter:
RANDINT(a,b,c) is the same as
RANDINT(a,c,b).

Congratulations, you found a bug! If the lower limit is negative, it will never be returned; furthermore, if the upper limit is also negative, then the result will sometimes be one greater than the upper limit:

RANDINT(5,-2,-3) --> {-2,-2,-1,-2,-1}
RANDINT(5,-4,-4) --> {-3,-3,-3,-3,-3}
(07-15-2014 12:58 AM)Joe Horn Wrote: [ -> ]RANDINT(5,-4,-4) --> {-3,-3,-3,-3,-3}

That is a good one! Thanks.
Reference URL's