PHPDaemon\Utils\Crypt::randomBytes PHP Method

randomBytes() public static method

Returns string of pseudo random bytes
public static randomBytes ( integer $len, callable $cb, integer $pri, boolean $hang = false ) : integer
$len integer Length of desired string
$cb callable Callback
$pri integer Priority of EIO operation
$hang boolean If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay
return integer
    public static function randomBytes($len, $cb, $pri = 0, $hang = false)
    {
        $cb = CallbackWrapper::wrap($cb);
        FileSystem::open('/dev/' . ($hang ? '' : 'u') . 'random', 'r', function ($file) use($len, $cb, $pri) {
            if (!$file) {
                $cb(false);
                return;
            }
            $file->read($len, 0, function ($file, $data) use($cb) {
                $cb($data);
            }, $pri);
        }, null, $pri);
    }