/** * Returns a random float between 0 and 1. * * @return float */ public static function getRandomFloat() { // The maximum precision on this platform. $maximumPrecision = strlen('' . 1 / 3) - 2; $float = ''; for ($a = 0; $a < $maximumPrecision; $a++) { $float .= Security_Randomizer::getRandomInteger(0, 9); } // All numbers are 0. if (array_sum(str_split($float)) == 0) { $float = (Security_Randomizer::getRandomBoolean() ? '1.' : '0.') . $float; } else { $float = '0.' . $float; } return (double) $float; }