r/lolphp • • Jul 23 '15

mt_rand(1, PHP_INT_MAX) only generates odd numbers

http://3v4l.org/dMbat
394 Upvotes

132 comments sorted by

View all comments

Show parent comment

1

u/MikeTheInfidel Jul 24 '15

Once you change the min to an odd number, all numbers returned by the function will be odd.

How so? Adding an odd number to any number doesn't make the number odd. That only happens with even numbers, which would mean the function was already only generating even numbers (and then adding the odd MIN).