public static function secure_random_string($length = 16)
    {
        if (function_exists('openssl_random_pseudo_bytes')) {
            $bytes = openssl_random_pseudo_bytes($length * 2);

            if ($bytes === false) {
                throw new \LengthException('$length is not accurate, unable to generate random string');
            }

            return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
        }

        // @codeCoverageIgnoreStart
        return static::random_string($length);
        // @codeCoverageIgnoreEnd
    }
public static function secure_random_string($length = 16)
    {
        if (function_exists('openssl_random_pseudo_bytes')) {
            $bytes = openssl_random_pseudo_bytes($length * 2);

            if ($bytes === false) {
                throw new \LengthException('$length is not accurate, unable to generate random string');
            }

            return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
        }

        // @codeCoverageIgnoreStart
        return static::random_string($length);
        // @codeCoverageIgnoreEnd
    }
public static function secure_random_string ( $ length = 16 ) { if ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ bytes = openssl_random_pseudo_bytes ( $ length * 2 ) ; if ( $ bytes === false ) { throw new \ LengthException ( '$length is not accurate, unable to generate random string' ) ; } return substr ( str_replace ( array ( '/' , '+' , '=' ) , '' , base64_encode ( $ bytes ) ) , 0 , $ length ) ; } // @codeCoverageIgnoreStart return static :: random_string ( $ length ) ; // @codeCoverageIgnoreEnd }
Generate secure random string of given length
If 'openssl_random_pseudo_bytes' is not available
then generate random string using default function

Part of the Laravel Project <https://github.com/laravel/laravel>

@param int $length length of string
@return bool
Generate secure random string of given length If openssl_random_pseudo_bytes is not available then generate random string using default function