How does one generate a random float between 0 and 1 in PHP?
I'm looking for the PHP's equivalent to Java's Math.random().
Math.random()
You may use the standard function: lcg_value().
Here's another function given on the rand() docs:
// auxiliary function // returns random number with flat distribution from 0 to 1 function random_0_1() { return (float)rand() / (float)getrandmax(); }
1.4m articles
1.4m replys
5 comments
57.0k users