src/Marando/Color/Color.php
public static function rand($h = [0, 360], $s = [0, 1], $l = [0, 1])
    {
        // Validate input criteria
        static::validateComp('H low', $h[0], 0, 360);
        static::validateComp('S low', $s[0], 0, 1);
        static::validateComp('L low', $l[0], 0, 1);
        static::validateComp('H high', $h[1], 0, 360);
        static::validateComp('S high', $s[1], 0, 1);
        static::validateComp('L high', $l[1], 0, 1);

        // Loop until calculated random HSL -> RGB -> HSL value matches params.
        $i = 0;
        while (true) {
            // Random HSL color
            $color = static::hsl(
              static::randFloat($h[0], $h[1], 1),
              static::randFloat($s[0], $s[1], 0.001),
              static::randFloat($l[0], $l[1], 0.001)
            );

            // Check if the HSL matches the input criteria
            $hMatch = $color->h >= $h[0] && $color->h <= $h[1];
            $sMatch = $color->s >= $s[0] && $color->s <= $s[1];
            $lMatch = $color->l >= $l[0] && $color->l <= $l[1];

            if ($hMatch && $sMatch && $lMatch) {
                // Match found...
                break;
            } elseif ($i > 50) {
                // Stop if not found by now.
                throw new Exception();
                break;
            } else {
                $i++;
            }
        }

        return $color;
    }
public static function rand($h = [0, 360], $s = [0, 1], $l = [0, 1])
    {
        // Validate input criteria
        static::validateComp('H low', $h[0], 0, 360);
        static::validateComp('S low', $s[0], 0, 1);
        static::validateComp('L low', $l[0], 0, 1);
        static::validateComp('H high', $h[1], 0, 360);
        static::validateComp('S high', $s[1], 0, 1);
        static::validateComp('L high', $l[1], 0, 1);

        // Loop until calculated random HSL -> RGB -> HSL value matches params.
        $i = 0;
        while (true) {
            // Random HSL color
            $color = static::hsl(
              static::randFloat($h[0], $h[1], 1),
              static::randFloat($s[0], $s[1], 0.001),
              static::randFloat($l[0], $l[1], 0.001)
            );

            // Check if the HSL matches the input criteria
            $hMatch = $color->h >= $h[0] && $color->h <= $h[1];
            $sMatch = $color->s >= $s[0] && $color->s <= $s[1];
            $lMatch = $color->l >= $l[0] && $color->l <= $l[1];

            if ($hMatch && $sMatch && $lMatch) {
                // Match found...
                break;
            } elseif ($i > 50) {
                // Stop if not found by now.
                throw new Exception();
                break;
            } else {
                $i++;
            }
        }

        return $color;
    }
public static function rand ( $ h = [ 0 , 360 ] , $ s = [ 0 , 1 ] , $ l = [ 0 , 1 ] ) { // Validate input criteria static :: validateComp ( 'H low' , $ h [ 0 ] , 0 , 360 ) ; static :: validateComp ( 'S low' , $ s [ 0 ] , 0 , 1 ) ; static :: validateComp ( 'L low' , $ l [ 0 ] , 0 , 1 ) ; static :: validateComp ( 'H high' , $ h [ 1 ] , 0 , 360 ) ; static :: validateComp ( 'S high' , $ s [ 1 ] , 0 , 1 ) ; static :: validateComp ( 'L high' , $ l [ 1 ] , 0 , 1 ) ; // Loop until calculated random HSL -> RGB -> HSL value matches params. $ i = 0 ; while ( true ) { // Random HSL color $ color = static :: hsl ( static :: randFloat ( $ h [ 0 ] , $ h [ 1 ] , 1 ) , static :: randFloat ( $ s [ 0 ] , $ s [ 1 ] , 0.001 ) , static :: randFloat ( $ l [ 0 ] , $ l [ 1 ] , 0.001 ) ) ; // Check if the HSL matches the input criteria $ hMatch = $ color -> h >= $ h [ 0 ] && $ color -> h <= $ h [ 1 ] ; $ sMatch = $ color -> s >= $ s [ 0 ] && $ color -> s <= $ s [ 1 ] ; $ lMatch = $ color -> l >= $ l [ 0 ] && $ color -> l <= $ l [ 1 ] ; if ( $ hMatch && $ sMatch && $ lMatch ) { // Match found... break ; } elseif ( $ i > 50 ) { // Stop if not found by now. throw new Exception ( ) ; break ; } else { $ i ++ ; } } return $ color ; }
Generates a random color. Minimum and maximum values are specified for
all of the HSL components.

@param array $h Random hue min/max, 0-360
@param array $s Random saturation min/max, 0-1
@param array $l Random lightness min/max, 0-1

@return Color
@throws Exception
Generates a random color . Minimum and maximum values are specified for all of the HSL components .