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:

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.

Activity

Zac Spitzer 4 April 2019 at 13:12

this was discussed again on the mailing list https://dev.lucee.org/t/randrange-limit/5375

Igal Sapir 4 September 2016 at 17:39

What's the behavior for this in ACF?

Andrew Dixon 17 April 2016 at 20:27

- Changed to enhancement as while it is erroring at that value, the other changes are an enhancement and would fix it as a side effect.

Ryan Guill 17 April 2016 at 19:48

I was offering to code it over a year ago, im not sure im offering to do that now.

I also don't understand the enhancement instead of bug designation - it returns numbers outside of the specified range.

Andrew Dixon 17 April 2016 at 19:28

- One for the TAG to discuss. Personally I think both suggestion are fine and is offering to code it.

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 31 January 2015 at 23:31
Updated 15 July 2024 at 15:39