Using standard lib version of randstr.php, which is more flexible and fast

This commit is contained in:
pezcurrel 2023-12-28 12:29:52 +01:00
parent 9440903626
commit e5b56f3e68

View file

@ -1,12 +1,11 @@
<?php
function randstr($len) {
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_:;\'"%&/?^';
$charslen=strlen($chars);
function randstr($len,$chars=null) {
if (is_null($chars))
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_:;\'"%&/?^';
$charslen=strlen($chars)-1;
$str='';
for ($i=0; $i<$len; $i++)
$str.=$chars[rand(0,$charslen-1)];
$str.=$chars[mt_rand(0,$charslen)];
return($str);
}
?>