Skip to content

Instantly share code, notes, and snippets.

@insideone
Created May 15, 2016 13:24
Show Gist options
  • Save insideone/8dd90437c62b3f5343c8eadcdc8cdb14 to your computer and use it in GitHub Desktop.
Save insideone/8dd90437c62b3f5343c8eadcdc8cdb14 to your computer and use it in GitHub Desktop.
PHP: rand_string
<?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