rand

@param int $length

@return string
485605
public static function rand($length)
    {
        if (!is_int($length)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Str::rand() expects first argument to be integer, instead saw %s.',
                    gettype($length)
                )
            );
        }

        if (!function_exists('openssl_random_pseudo_bytes')) {
            return self::quickRand($length);
        }

        if (null === ($bytes = openssl_random_pseudo_bytes($length * 2))) {
            throw new \RuntimeException('Cannot generate random string');
        }

        return substr(str_replace(['/', '=', '+'], '', base64_encode($bytes)), 0, $length);
    }
1069751
public static function random($length = 64, $characters = self::ALNUM)
    {
        static $random_generator = null;

        if (null === $random_generator) {
            $random_generator = is_callable('mt_rand') ? 'mt_rand' : 'rand';
        }

        $len = strlen($characters);
        return join(
            '',
            array_map(
                function () use ($characters, $len, $random_generator) {
                    return $characters{$random_generator(0, $len - 1)};
                },
                range(0, $length - 1)
            )
        );
    }
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;
    }
447050
public static function randomString(int $length, $characters = null): string
    {
        if (is_null($characters)) {
            $characters = array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'));
        }
        if (is_string($characters)) {
            $characters = str_split($characters);
        }
        $result = '';
        $characterCount = count($characters);
        for ($i = 0; $i < $length; ++$i) {
            $result .= $characters[self::randomInt(0, $characterCount - 1)];
        }
        return $result;
    }
143195
public static function randomLatinNumeric(int $length): string
    {
        $ret = 97;
        $out = null;
        for ($i = 0; $i < $length; $i++) {
            $offset = mt_rand(0, 15);
            $char = chr($ret + $offset);
            $posibility = mt_rand(0, 2);
            if ($posibility == 0) {
                // 33% - add random numeric
                $out .= mt_rand(0, 9);
            } elseif ($posibility == 1) {
                // 33% - make upper offset+ret
                $out .= strtoupper($char);
            } else {
                $out .= $char;
            }
        }
        return $out;
    }
529584
public static function createRandomAlphaNumeric($length = 8)
    {
        $chars  = array("abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "123456789");
        $count  = array((strlen($chars[0]) - 1), (strlen($chars[1]) - 1));
        $prefix = "";
        for ($i = 0; $i < $length; $i++) {
            $type = mt_rand(0, 1);
            $prefix .= substr($chars[$type], mt_rand(0, $count[$type]), 1);
        }
        return self::create($prefix);
    }
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());
    }
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;
    }
834989
public function random_string($length = 32)
    {
        return substr(str_shuffle(str_repeat(
            $x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
            ceil($length / strlen($x))
        )), 1, $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);
    }
822903
public static function randomFrom(string $pool, $length = 8): string
    {
        $str        = '';
        $poolLength = strlen($pool);
        for ($i = 0; $i < $length; $i++) {
            $str .= $pool[mt_rand(0, $poolLength - 1)];
        }

        return $str;
    }
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;
    }
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;
    }
728272
private function random(int $length = 32): string
    {
        try {
            if (empty($string = random_bytes($length))) {
                throw new \RuntimeException("Unable to generate random string");
            }
        } catch (\Throwable $e) {
            throw new \RuntimeException("Unable to generate random string", $e->getCode(), $e);
        }

        return substr(base64_encode($string), 0, $length);
    }
166955
public static function random($length = 4)
    {
        $reqid = '';
        $characters = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", "8", "9"];
        shuffle($characters);
        for (; strlen($reqid) < $length;) {
            $reqid .= $characters[rand(0, count($characters) - 1)];
        }
        return $reqid;
    }
1057248
public static function genRandomPassword($length = 8)
	{
		$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		$base = strlen($salt);
		$makepass = '';

		// Start with a cryptographic strength random string, then convert it to
		// a string with the numeric base of the salt.
		// Shift the base conversion on each character so the character
		// distribution is even, and randomize the start shift so it's not
		// predictable.
		$random = \Hubzero\Encryption\Encrypter::genRandomBytes($length + 1);
		$shift = ord($random[0]);
		for ($i = 1; $i <= $length; ++$i)
		{
			$makepass .= $salt[($shift + ord($random[$i])) % $base];
			$shift += ord($random[$i]);
		}

		return $makepass;
	}
730283
public static function random62($length)
    {
        $str = self::DIGIT.self::ALPHABET;
        
        $strLength = 62;
        while($length > $strLength){
            $str .= $str;
            $strLength += 60;
        }
        
        $str = str_shuffle($str);
        return substr($str, 0,$length);
    }