Created
May 15, 2016 13:24
-
-
Save insideone/8dd90437c62b3f5343c8eadcdc8cdb14 to your computer and use it in GitHub Desktop.
PHP: rand_string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Возвращает строку с случайными буквами английского алфавита и цифрами установленной длины | |
* @param int $lenght Необходимая длина | |
*/ | |
function rand_string($lenght = 32) | |
{ | |
$N = 1 + (int)($lenght / 30); | |
for ($i = 0; $i < $N; $i++) | |
{ | |
$result .= base_convert(sha1(mt_rand()), 16, 36); | |
} | |
$result = substr($result, 0, $lenght); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment