b3ta.com board
You are not logged in. Login or Signup
Home » Messageboard » XXX » Message 9401807 (Thread)

# That makes sense (though you'd need $r instead of r)!
That said, rand()%$max is generally unwise as it skews the distribution. (rand()/getrandmax())*$max won't skew the distribution. PHP also provides a rand($min, $max) overload - I'm not sure which method that uses, but it's probably easier to use that!
(, Tue 28 Apr 2009, 14:13, archived)
# Gaaaahhhh!!! The more I look, the worse it gets!
PHP:rand() says:  "On some platforms (such as Windows), getrandmax() is only 32768."
WHAT??!!! That's like helpfully including free exploding poisoned razor blades with the programming language you ordered!

"... consider using mt_rand() instead."
It depends what you want the pseudo-randomness for, but if patterning will have a serious bad effect, you might want to use mt_rand() instead. Don't forget to think about how it is seeded, too!
(, Tue 28 Apr 2009, 14:33, archived)