We're updating the issue view to help you get more done. 

randRange() int overflow

Description

randRange() only works with int's, but if you use a MAX_INT as the max value, it will overflow the integer and wrap around, giving you a value that is not between the supplied values:

example:

1 writedump(randRange(0,2^31-1)) // -1605445948 - just an example, different negative values each time

I propose a few tweaks.

  1. Change to use longs instead of integers. I have the need to get random numbers much larger already.

  2. Throw an error if the values are outside of expected ranges and would cause a return value outside of the provided range.

If it is acceptable to do both of these items, I would be happy to make the changes myself and submit a pull request for the code and a test.

Status

Assignee

Brad Wood

Reporter

Ryan Guill

Priority

Minor