按UNIX时间戳产生随机数
@param $rand_length
@return string
967499
static function randtime($rand_length = 6)
    {
        list($usec, $sec) = explode(" ", microtime());
        $min = intval('1' . str_repeat('0', $rand_length - 1));
        $max = intval(str_repeat('9', $rand_length));
        return substr($sec, -5) . ((int)$usec * 100) . rand($min, $max);
    }
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;
    }
536740
public static function getRandomString($length = 20, $chars = self::RAND_BASIC): string
    {
        return substr(str_shuffle(str_repeat($chars, (int)ceil((int)(strlen($chars) / $length)))), 0, $length);
    }
628142
def _get_random_string(length=44,
                       allowed_chars='abcdefghijklmnopqrstuvwxyz'
                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
                       secret_key=settings.secret_key_bytes()):
    
    secret_key = _ensure_bytes(secret_key)
    _reseed_if_needed(using_sysrandom, secret_key)
    return ''.join(random.choice(allowed_chars) for i in range(length))
898657
public static function generateSalt($length = 32)
	{
		$salt = '';

		for($i = 0; $i < $length; ++$i)
			$salt .= chr(rand(0,127));

		return $salt;
	}
487746
private function bigRandomNumber($randNumberLength)
    {
        $randNumber = null;

        for ($i = 0; $i < $randNumberLength; $i++) {
            $randNumber .= rand(0, 9);
        }

        return $randNumber;
    }
1148518
protected function generate($length = null)
    {
        $generator = new RandomGenerator();
        $result = $generator->randomToken('sha256');
        if ($length !== null) {
            return substr($result, 0, $length);
        }
        return $result;
    }
1346506
protected static function generateSalt(): string
    {
        $result = '';

        static::validateSaltMinLength();

        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $poolSize = strlen($pool);
        for ($i = 0; $i < static::$saltMinLength; $i++) {
            $result .= $pool[rand(0, $poolSize - 1)];
        }

        return $result;
    }
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.');
	}
1078518
static function getRandomString($length = 8)
    {

        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        $value = '';
        $charsLength = strlen($chars) - 1;

        for ($i = 1 ; $i <= $length; $i++) {
            $value .= $chars[rand(0, $charsLength)];
        }

        return $value;

    }
1353271
private function randCode($length = 6, $type = 'mix')
    {
        $number = '0123456789';
        $seed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $specialChar = '!@#$%^&*()_+[]|';
        $randRes = "";
        switch ($type) {
            case 'string':
                for ($i = 0; $i < $length; $i++)
                {
                    $randomInt = rand(0, strlen($seed) - 1);
                    $randRes .= $seed{$randomInt};
                }
                break;
            case 'number':
                for ($i = 0; $i < $length; $i++)
                {
                    $randomInt = rand(0, strlen($number) - 1);
                    $randRes .= $number{$randomInt};
                }
                break;
            case 'mix':
                $mix = $number . $seed;
                for ($i = 0; $i < $length; $i++)
                {
                    $randomInt = rand(0, strlen($mix) - 1);
                    $randRes .= $mix{$randomInt};
                }
                break;
            case 'special':
                $special = $number . $seed . $specialChar;
                for ($i = 0; $i < $length; $i++)
                {
                    $randomInt = rand(0, strlen($special) - 1);
                    $randRes .= $special{$randomInt};
                }
                break;
        }
        return $randRes;
    }
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;
	}
1226170
public static function random_password($length = 8)
	{
		$genpass = '';
		$salt = "abchefghjkmnpqrstuvwxyz0123456789";

		srand((double)microtime()*1000000);

		$i = 0;

		while ($i < $length)
		{
			$num = rand() % 33;
			$tmp = substr($salt, $num, 1);
			$genpass = $genpass . $tmp;
			$i++;
		}

		return $genpass;
	}
40063
public function string(int $length = 8)
    {
        $list = 'abcdefghijklmnopqrstuvwxyz';
        $return = '';
        for ($i = 0; $i < $length; $i++) {
            $return .= $list[rand(0, strlen($list) - 1)];
        }

        return $return;
    }
419938
def get_rand_string(length=12, allowed_chars='0123456789abcdef'):
    
    if not using_sysrandom:
        # This is ugly, and a hack, but it makes things better than
        # the alternative of predictability. This re-seeds the PRNG
        # using a value that is hard for an attacker to predict, every
        # time a random string is required. This may change the
        # properties of the chosen random sequence slightly, but this
        # is better than absolute predictability.
        random.seed(
            hashlib.sha256(
                ("%s%s" % (
                    random.getstate(),
                    time.time())).encode('utf-8')
            ).digest())
    return ''.join([random.choice(allowed_chars) for i in range(length)])
773025
public 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 = Crypt::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;
    }
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;
    }