public static function randomBytes($length)
    {
        if (function_exists('random_bytes')) {
            return random_bytes($length);
        }
        if (!function_exists('openssl_random_pseudo_bytes')) {
            throw new RuntimeException(
                'You do not have a safe source of random data available. ' .
                'Install either the openssl extension, or paragonie/random_compat. ' .
                'Or use Security::insecureRandomBytes() alternatively.'
            );
        }

        $bytes = openssl_random_pseudo_bytes($length, $strongSource);
        if (!$strongSource) {
            trigger_error(
                'openssl was unable to use a strong source of entropy. ' .
                'Consider updating your system libraries, or ensuring ' .
                'you have more available entropy.',
                E_USER_WARNING
            );
        }

        return $bytes;
    }
public static function randomBytes($length)
    {
        if (function_exists('random_bytes')) {
            return random_bytes($length);
        }
        if (!function_exists('openssl_random_pseudo_bytes')) {
            throw new RuntimeException(
                'You do not have a safe source of random data available. ' .
                'Install either the openssl extension, or paragonie/random_compat. ' .
                'Or use Security::insecureRandomBytes() alternatively.'
            );
        }

        $bytes = openssl_random_pseudo_bytes($length, $strongSource);
        if (!$strongSource) {
            trigger_error(
                'openssl was unable to use a strong source of entropy. ' .
                'Consider updating your system libraries, or ensuring ' .
                'you have more available entropy.',
                E_USER_WARNING
            );
        }

        return $bytes;
    }
public static function randomBytes ( $ length ) { if ( function_exists ( 'random_bytes' ) ) { return random_bytes ( $ length ) ; } if ( ! function_exists ( 'openssl_random_pseudo_bytes' ) ) { throw new RuntimeException ( 'You do not have a safe source of random data available. ' . 'Install either the openssl extension, or paragonie/random_compat. ' . 'Or use Security::insecureRandomBytes() alternatively.' ) ; } $ bytes = openssl_random_pseudo_bytes ( $ length , $ strongSource ) ; if ( ! $ strongSource ) { trigger_error ( 'openssl was unable to use a strong source of entropy. ' . 'Consider updating your system libraries, or ensuring ' . 'you have more available entropy.' , E_USER_WARNING ) ; } return $ bytes ; }
Get random bytes from a secure source.

This method will fall back to an insecure source an trigger a warning
if it cannot find a secure source of random data.

@param int $length The number of bytes you want.
@return string Random bytes in binary.
Get random bytes from a secure source .