src/Phpass/Hash/Adapter/Base.php
protected function _getRandomBytes($count)
    {
        if (!is_int($count) || $count < 1) {
            throw new InvalidArgumentException('Argument must be a positive integer');
        }

        // Try OpenSSL's random generator
        if (function_exists('openssl_random_pseudo_bytes')) {
            $strongCrypto = false;
            $output = openssl_random_pseudo_bytes($count, $strongCrypto);
            if ($strongCrypto && strlen($output) == $count) {
                return $output;
            }
        }

        // Try reading from /dev/urandom, if present
        $output = '';
        if (is_readable('/dev/urandom') && ($fh = fopen('/dev/urandom', 'rb'))) {
            $output = fread($fh, $count);
            fclose($fh);
        }

        // Fall back to a locally generated "random" string
        if (strlen($output) < $count) {
            $output = '';
            for ($i = 0; $i < $count; $i += 16) {
                $this->_randomState = md5(microtime() . $this->_randomState);
                $output .= md5($this->_randomState, true);
            }
            $output = substr($output, 0, $count);
        }

        return $output;
    }
protected function _getRandomBytes($count)
    {
        if (!is_int($count) || $count < 1) {
            throw new InvalidArgumentException('Argument must be a positive integer');
        }

        // Try OpenSSL's random generator
        if (function_exists('openssl_random_pseudo_bytes')) {
            $strongCrypto = false;
            $output = openssl_random_pseudo_bytes($count, $strongCrypto);
            if ($strongCrypto && strlen($output) == $count) {
                return $output;
            }
        }

        // Try reading from /dev/urandom, if present
        $output = '';
        if (is_readable('/dev/urandom') && ($fh = fopen('/dev/urandom', 'rb'))) {
            $output = fread($fh, $count);
            fclose($fh);
        }

        // Fall back to a locally generated "random" string
        if (strlen($output) < $count) {
            $output = '';
            for ($i = 0; $i < $count; $i += 16) {
                $this->_randomState = md5(microtime() . $this->_randomState);
                $output .= md5($this->_randomState, true);
            }
            $output = substr($output, 0, $count);
        }

        return $output;
    }
protected function _getRandomBytes ( $ count ) { if ( ! is_int ( $ count ) || $ count < 1 ) { throw new InvalidArgumentException ( 'Argument must be a positive integer' ) ; } // Try OpenSSL's random generator if ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ strongCrypto = false ; $ output = openssl_random_pseudo_bytes ( $ count , $ strongCrypto ) ; if ( $ strongCrypto && strlen ( $ output ) == $ count ) { return $ output ; } } // Try reading from /dev/urandom, if present $ output = '' ; if ( is_readable ( '/dev/urandom' ) && ( $ fh = fopen ( '/dev/urandom' , 'rb' ) ) ) { $ output = fread ( $ fh , $ count ) ; fclose ( $ fh ) ; } // Fall back to a locally generated "random" string if ( strlen ( $ output ) < $ count ) { $ output = '' ; for ( $ i = 0 ; $ i < $ count ; $ i += 16 ) { $ this -> _randomState = md5 ( microtime ( ) . $ this -> _randomState ) ; $ output .= md5 ( $ this -> _randomState , true ) ; } $ output = substr ( $ output , 0 , $ count ) ; } return $ output ; }
Generate a pseudo-random string of bytes.

@param integer $count
The length of the desired string of bytes. Must be a positive integer.
@return string
Returns the generated string of bytes.
@throws InvalidArgumentException
Thows an InvalidArgumentException if the $count parameter is not a
positive integer.
Generate a pseudo - random string of bytes .