Force to have something of the expected size (block).

@param $length

@return string
334009
private function forceRead($length)
    {
        $read = '';

        do {
            $read .= $this->stream->read($length - \strlen($read));
        } while (\strlen($read) < $length && !$this->stream->eof());

        return $read;
    }
958150
public function appendSpace($length)
    {
        $paddingLength = (int) $length;
        $this->message = $this->message . str_pad('', $paddingLength, ' ');

        return $this;
    }
758250
public function read($length)
    {
        if ($length < 0) {
            throw new DomainAssertion('Length cannot be negative');
        }
        if ($length == 0) {
            return '';
        }
        $this->checkStreamAvailable();
        return fread($this->fileDescriptor, $length);
    }
653185
protected function generateNonce( $length = 32 )
    {
        $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $result = '';
        for ( $i = 0; $i < $length; $i++ )
        {
            $result .= $chars[mt_rand( 0, strlen( $chars ) - 1 )];
        }

        return $result;
    }
599538
private static function generateRandomString($length = 10)
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $string = '';

        for ($i = 0; $i < $length; $i++) {
            $string .= $characters[rand(0, strlen($characters) - 1)];
        }

        return $string;
    }
1294007
public static function random($length) {
        $res = '';
        for ($i = 0; $i < $length; $i++) {
            $res .= chr(mt_rand(33, 126));
        }
        return $res;
    }
360287
public function setLength($length)
    {
        $length = intval($length);
        $this->length = empty($length) ? 1 : $length;

        return $this;
    }
935379
public function read(int $length = 8192): string
    {
        $isAcceptable = $this->predicate;
        while (!$this->inputStream->eof()) {
            $data = $this->inputStream->read($length);
            if ($isAcceptable($data)) {
                return $data;
            }
        }

        return '';
    }
223863
public static function generateRandomNumberString($length = 6)
    {
        $result = '';

        for ($index = 0; $index < $length; $index++) {
            $result .= mt_rand(0, 9);
        }

        return $result;
    }
686260
public static function random(int $length): string
    {
        $byteLength = ($length < 10) ? 10 : $length;
        $chars = base64_encode(random_bytes($byteLength));
        $chars = str_replace(["+", "/", "="], "", $chars);
        return substr($chars, 0, $length);
    }
743789
private function randomToken($length = 32)
    {
        if (!isset($length) || intval($length) <= 8) {
            $length = 32;
        }
        if (function_exists('random_bytes')) {
            return random_bytes($length);
        }
        if (function_exists('mcrypt_create_iv')) {
            return mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
        }
        if (function_exists('openssl_random_pseudo_bytes')) {
            return openssl_random_pseudo_bytes($length);
        }

        return @crypt(uniqid());
    }
985373
private function fillBuffer($length)
    {
        $fill = intval(max([$length, 8192]));
        while ($this->buffer->getSize() < $length) {
            $read = $this->stream->read($fill);
            if ($read === false || $read === '') {
                break;
            }
            $this->buffer->write(preg_replace($this->pattern, $this->replacement, $read));
        }
    }
679625
protected function _bufferSize($length)
    {
        if ($this->_limit !== null) {
            $position = $this->tell();
            $max = $this->_start + $this->_limit;
            $length = $max - $position;
        }
        if ($length === null) {
            $length = $this->_bufferSize;
        }
        return $length;
    }
519732
public static function randomString($length)
    {
        $key = '';
        $keys = array_merge(range('a', 'z'));

        for ($i = 0; $i < $length; ++$i) {
            $key .= $keys[array_rand($keys)];
        }

        return $key;
    }
1299554
public static function getUniqueId($length = 20): string
    {
        try {
            return substr(bin2hex(random_bytes($length)), 0, $length);
        } catch (Exception $exception) {
            return self::getRandomString($length);
        }
    }
861888
public function maxLength(int $length) : Element
    {
        $this->attributes['maxlength'] = (int)$length;
        return $this->addTest('maxlength', function($value) use ($length) {
            return mb_strlen(trim($value), 'UTF-8') <= (int)$length;
        });
    }
49127
public function protectedEncodeASN1Length($length)
    {
        if ($length <= 0x7F) {
            return chr($length);
        }
        $temp = ltrim(pack('N', $length), chr(0));
        return pack('Ca*', 0x80 | strlen($temp), $temp);
    }