@param int $length

@return string|null
179313
public function resetUserPassword($length = 256)
    {
        // resets user's password, and returns the value of the reset password
        if ($this->getUserID() > 0) {
            $id = $this->application->make(Identifier::class);
            $newPassword = $id->getString($length);
            $this->changePassword($newPassword);

            $ue = new UserInfoEvent($this);
            $this->getDirector()->dispatch('on_user_reset_password', $ue);

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

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

        return $result;
    }
483675
public function withMaxLength(int $length): self
    {
        $obj = clone $this;
        $obj->_maxLength = $length;
        return $obj;
    }
865236
static public function randomStr($length)
    {
        $str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $strlen = 62;
        while ($length > $strlen) {
            $str .= $str;
            $strlen += 60;
        }
        $str = str_shuffle($str);

        return substr($str, 0, $length);
    }
1083447
static public function EncodeLength($length)
    {
        self::CheckMessageLength($length);

        $string = "";
        do{
            $digit = $length % 0x80;
            $length = $length >> 7;
            // if there are more digits to encode, set the top bit of this digit
            if ( $length > 0 ) $digit = ($digit | 0x80);
            $string .= chr($digit);
        } while ( $length > 0 );

        return $string;
    }
108362
public function readLine(int $length = 8192): string
    {
        return iconv($this->charset, 'UTF-8', $this->inputStream->readLine($length));
    }
133940
static function random($length) {
        if (!is_numeric($length)) return null;
        
        $chars = str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(1, 4));
        
        return substr(str_shuffle($chars), 0, $length);
    }
100426
public static function getStrongPseudoRandomBytes(int $length): string {
        $result = openssl_random_pseudo_bytes($length, $strong);
        if(!$strong) {
            throw new RuntimeException('Not strong enough');
        }
        return $result;
    }
406662
public function randomNumbers($length = 6)
    {
        $nums = '0123456789';

        $out = $nums[mt_rand(1, strlen($nums)-1)];

        for ($p = 0; $p < $length-1; $p++) {
            $out .= $nums[mt_rand(0, strlen($nums)-1)];
        }

        return $out;
    }
449682
public function getAbstract($length = 100)
    {
        $content = $this->getContent();
        if (mb_strlen($content) > $length - 3) {
            return mb_substr($content, 0, $length - 3) . '...';
        } else {
            return $content;
        }
    }
1232624
public static function GenerateRandomString(int $length = 20)
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
58141
public function getRandomString(int $length = 64): string
    {
        $chars  = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()';
        $random = '';

        for ($i = 0; $i < $length; $i++) {
            $random .= substr($chars, random_int(0, strlen($chars) - 1), 1);
        }

        return $random;
    }
432622
private function hash(int $length):string {
		$char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; // strlen($char) = 62
		$hash = '';
		for( $i=0; $i < $length; $i++ )
			$hash .= $char[random_int(0,61)];
		return $hash;
	}
862458
public function generateRandomString($length)
    {
        do {
            $bytes = base64_encode($this->random->nextBytes($length));
            $string = substr(strtr($bytes, array('+' => '', '/' => '', '=' => '')), 0, $length);
        } while (strlen($string) < $length);
        return $string;
    }
1149284
public static function rand($length)
    {
        $chars = '~)!abc}def#ghijkl[m-no.pqrs]tu;v|wx+yzA%BC(D:EF{GHI&JKLM=NOP*QRS?TU4567VWXYZ_012389' .uniqid();
        $str   =  '';
        $size  = strlen($chars);

        for ($i = 0; $i < $length; $i++) {
            $str .= $chars[rand(0, $size - 1)];
        }
        
        return $str;
    }
214880
public function read(int $length = null): string
    {
        // can not call fgets with null when not specified
        $data = null === $length ? fgets($this->resource) : fgets($this->resource, $length);
        if (false === $data) {
            // fgets() returns false on eof while feof() returned false before
            // but will now return true
            if ($this->eof()) {
                return '';
            }

            if (stream_get_meta_data($this->resource)['timed_out']) {
                throw new Timeout(
                        'Reading of ' . $length . ' bytes failed: timeout of '
                        . $this->timeout . ' seconds exceeded'
                );
            }

            throw new ConnectionFailure(
                    'Reading of ' . $length . ' bytes failed.'
            );
        }

        return $data;
    }
795786
public function stream_read($length)
    {
        $data = substr($this->_data, $this->_position, $length);
        $this->_position += strlen($data);

        return $data;
    }