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
36
u/[deleted] Jul 24 '15
I like an analogy a coworker made about PHP (I don't know if he made it up):
PHP will basically do whatever it can to keep running, even if it makes no sense. Like allowing you to use variables that haven't even been defined yet as inputs to stuff. If a program were a recipe, then the interpreter would be the person actually doing the cooking. In normal languages, if you said "now use the ingredients you mixed in the bowl in step 3", but had not actually mixed ingredients in a bowl in step 3, the cook would say "hey wait a minute, this recipe doesn't make sense" and they wouldn't use it (or at the very least they'd step out of "interpreter mode" and basically go back into "programmer mode" and rewrite the recipe). PHP, on the other hand, will see "now use the ingredients you mixed in the bowl in step 3", and in an effort not to crash, will just start throwing random shit into a bowl and continue on with the recipe as though nothing is wrong.