Random Float between 0 and 1 in PHP

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();
}

Leave a Comment