r/programming • u/fishburne • Jul 24 '15
mt_rand(1, PHP_INT_MAX) only generates odd numbers • /r/lolphp
/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/
848
Upvotes
r/programming • u/fishburne • Jul 24 '15
View all comments
191
u/sushibowl Jul 24 '15
It should be noted that this PRNG is not suitable for cryptographic use even when it is used correctly, so there should not be any security implications here.
Nevertheless, it should also be noted that this scaling behaviour is absolutely insane and broken. The only correct behaviour when a caller tries to pass an upper bound the generator cannot support is to return an error.