src/Float.php
public static function random($min = 0.0, $max = 1.0, $round = null, $seed = null)
    {
        if (!static::is($min) || !static::is($max)) {
            throw new \InvalidArgumentException("The \$min and \$max parameters must be of type float.");
        }

        if ($min > $max) {
            trigger_error("The \$min value cannot be greater than the \$max value.", E_USER_WARNING);

            return false;
        }

        // If a seed was given use that seed
        !is_null($seed) && Int::is($seed) && mt_srand($seed);

        // Ensure that max is not inclusive
        $rand = $min + (((mt_rand() - 1) / mt_getrandmax()) * abs($max - $min));

        // Round if needed
        (!is_null($round) && Int::is($round) && $round > 0) && ($rand = round($rand, $round));

        // unseed (random reseed) random generator
        mt_srand();

        return $rand;
    }
public static function random($min = 0.0, $max = 1.0, $round = null, $seed = null)
    {
        if (!static::is($min) || !static::is($max)) {
            throw new \InvalidArgumentException("The \$min and \$max parameters must be of type float.");
        }

        if ($min > $max) {
            trigger_error("The \$min value cannot be greater than the \$max value.", E_USER_WARNING);

            return false;
        }

        // If a seed was given use that seed
        !is_null($seed) && Int::is($seed) && mt_srand($seed);

        // Ensure that max is not inclusive
        $rand = $min + (((mt_rand() - 1) / mt_getrandmax()) * abs($max - $min));

        // Round if needed
        (!is_null($round) && Int::is($round) && $round > 0) && ($rand = round($rand, $round));

        // unseed (random reseed) random generator
        mt_srand();

        return $rand;
    }
public static function random ( $ min = 0.0 , $ max = 1.0 , $ round = null , $ seed = null ) { if ( ! static :: is ( $ min ) || ! static :: is ( $ max ) ) { throw new \ InvalidArgumentException ( "The \$min and \$max parameters must be of type float." ) ; } if ( $ min > $ max ) { trigger_error ( "The \$min value cannot be greater than the \$max value." , E_USER_WARNING ) ; return false ; } // If a seed was given use that seed ! is_null ( $ seed ) && Int :: is ( $ seed ) && mt_srand ( $ seed ) ; // Ensure that max is not inclusive $ rand = $ min + ( ( ( mt_rand ( ) - 1 ) / mt_getrandmax ( ) ) * abs ( $ max - $ min ) ) ; // Round if needed ( ! is_null ( $ round ) && Int :: is ( $ round ) && $ round > 0 ) && ( $ rand = round ( $ rand , $ round ) ) ; // unseed (random reseed) random generator mt_srand ( ) ; return $ rand ; }
Generates a random float number between min and max.

The function will correct the min and max if inverted.

@param float    $min   Lower bound (inclusive)
@param float    $max   Upper bound (non-inclusive)
@param null|int $round Decimal places to round the number to (or null for no rounding)
@param null|int $seed  Random generator seed

@return float|false A random float value between min (or 0) and max (or 1, exclusive), or FALSE if max
is less than min.
@throws \InvalidArgumentException
Generates a random float number between min and max .