RANDINT parameters - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: HP Prime ( /forum-5.html)+--- Thread: RANDINT parameters ( /thread-1830.html) |

RANDINT parameters - Alberto Candel - 07-15-2014 12:22 AM
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. RE: RANDINT parameters - Joe Horn - 07-15-2014 12:58 AM
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} RE: RANDINT parameters - Alberto Candel - 07-15-2014 01:06 AM
(07-15-2014 12:58 AM)Joe Horn Wrote: RANDINT(5,-4,-4) --> {-3,-3,-3,-3,-3} That is a good one! Thanks. |