Get the specified number of random bytes, using mt_rand().
Randomness is returned as a string of bytes.

@param integer $bytes
@return string
516719
protected static function randomTwister($bytes)
    {
        $rand = "";
        for ($a = 0; $a < $bytes; $a++) {
            $rand .= chr(mt_rand(0, 255));
        }

        return $rand;
    }
579911
private function limitBytes($bytes)
    {
        if ($bytes === null) {
            return $this->content;
        } elseif (intval($bytes) < (self::BYTE_LIMIT * 0.046875)) {
            // less than 24 kilobytes (512 kilobytes * 0.046875)
            throw new \InvalidArgumentException('Byte limit is set dangerously low! Default value=' . self::BYTE_LIMIT);
        }
        return $this->content = mb_strcut($this->content, 0, intval($bytes));
    }
1374538
public static function randomUid($length = 16)
    {
        if(!isset($length) || intval($length) <= 8 ){
            $length = 16;
        }

        if (function_exists('random_bytes')) {
            return bin2hex(random_bytes($length));
        }

        if (function_exists('mcrypt_create_iv')) {
            return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
        }

        if (function_exists('openssl_random_pseudo_bytes')) {
            return bin2hex(openssl_random_pseudo_bytes($length));
        }
    }
995582
public static function randomBytes($length = 16) {
		if (PHP_MAJOR_VERSION >= 7 || defined('RANDOM_COMPAT_READ_BUFFER')) {
			return random_bytes($length);
		} elseif (function_exists('openssl_random_pseudo_bytes')) {
			$bytes = openssl_random_pseudo_bytes($length, $strong);
			if ($bytes === false || $strong === false) {
				throw new \InvalidArgumentException('Unable to generate random string.');
			}
			return $bytes;
		}
		throw new \ErrorException('OpenSSL extension or paragonie/random_compat is required for PHP 5 users.');
	}
226350
public function fromBytes($bytes)
    {
        for ($i=0; $bytes >= 1024 && $i < 8; $i++) {
            $bytes /= 1024;
        }
        return round($bytes, 2) . $this->units[$i];
    }
100350
protected function readBytes($bytes)
    {
        $data = '';
        $len  = 0;

        while ($len < $bytes && !$this->eof()) {
            $d = fread($this->fp, $bytes-$len);
            if ($this->debug) {
                $this->debug('S: '. $d);
            }
            $data .= $d;
            $data_len = strlen($data);
            if ($len == $data_len) {
                break; // nothing was read -> exit to avoid apache lockups
            }
            $len = $data_len;
        }

        return $data;
    }
958601
public static function int_rand($length,$one='')
    {
        $str = self::random_pseudo_bytes(32,10,$one);
        $strlen = strlen($str)-1;
        $results = '';
        for($i=1;$i<=$length;$i++){
            $results  .= $str{mt_rand(0,$strlen)};
        }


        return $results;
    }
945984
public static function fromBytes(array $bytes)
    {
        $result = null;
        if (count($bytes) === 16) {
            $address = '';
            for ($i = 0; $i < 16; ++$i) {
                if ($i !== 0 && $i % 2 === 0) {
                    $address .= ':';
                }
                $byte = $bytes[$i];
                if (is_int($byte) && $byte >= 0 && $byte <= 255) {
                    $address .= sprintf('%02x', $byte);
                } else {
                    $address = null;
                    break;
                }
            }
            if ($address !== null) {
                $result = new static($address);
            }
        }

        return $result;
    }
82976
public function read($bytes)
    {
        $data = substr($this->str, $this->pos, $bytes);

        $this->seekto($this->pos + $bytes);

        return $data;
    }
933918
public static function byteStringToInt($bytes)
    {
        if (!self::isSupported()) {
            throw new \RuntimeException('This utility is only supported on 64 bit machines with PHP version > 5.5.');
        }
        if (self::isSystemLittleEndian()) {
            $bytes = strrev($bytes);
        }
        return unpack("q", $bytes)[1];
    }
1106661
public static function generateRandom($length = 10)
    {
        $max = ceil($length / 40);
        $random = '';
        for ($i = 0; $i < $max; $i++) {
            $random .= sha1(microtime(true) . mt_rand(10000, 90000));
        }

        return substr($random, 0, $length);
    }
1294007
public static function random($length) {
        $res = '';
        for ($i = 0; $i < $length; $i++) {
            $res .= chr(mt_rand(33, 126));
        }
        return $res;
    }
283244
public function shift($bytes)
    {
        $bufferLen = strlen($this->buffer);

        if ($bytes === $bufferLen) {
            $return       = $this->buffer;
            $this->buffer = '';
        } else {
            $return       = substr($this->buffer, 0, $bytes);
            $this->buffer = substr($this->buffer, $bytes);
        }

        return $return;
    }
374283
protected function randomString($length)
	{
		$seed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijqlmnopqrtsuvwxyz0123456789';
		$max = strlen($seed) - 1;
		$string = '';
		for ($i = 0; $i < $length; ++$i) {
			$string .= $seed{intval(mt_rand(0.0, $max))};
		}

		return $string;
	}
663707
private static function sizeFormat($bytes)
    {
        $kb = 1024;
        $mb = $kb * 1024;
        $gb = $mb * 1024;
        $tb = $gb * 1024;

        if (($bytes >= 0) && ($bytes < $kb)) {
            return $bytes . ' B';
        } elseif (($bytes >= $kb) && ($bytes < $mb)) {
            return ceil($bytes / $kb) . ' KB';
        } elseif (($bytes >= $mb) && ($bytes < $gb)) {
            return ceil($bytes / $mb) . ' MB';
        } elseif (($bytes >= $gb) && ($bytes < $tb)) {
            return ceil($bytes / $gb) . ' GB';
        } elseif ($bytes >= $tb) {
            return ceil($bytes / $tb) . ' TB';
        } else {
            return $bytes . ' B';
        }
    }
1329656
function _random_number_helper($size)
    {
        if (class_exists('\phpseclib\Crypt\Random')) {
            $random = Random::string($size);
        } else {
            $random = '';

            if ($size & 1) {
                $random.= chr(mt_rand(0, 255));
            }

            $blocks = $size >> 1;
            for ($i = 0; $i < $blocks; ++$i) {
                // mt_rand(-2147483648, 0x7FFFFFFF) always produces -2147483648 on some systems
                $random.= pack('n', mt_rand(0, 0xFFFF));
            }
        }

        return new static($random, 256);
    }
1333533
public function write(string $bytes): int
    {
        return $this->outputStream->write(iconv('UTF-8', $this->charset, $bytes));
    }