note 125014 added to function.random-bytes
| From: | ccb2357 at gmail dot com | Date: | Fri, 15 May 2020 15:49:01 +0000 |
| Subject: | note 125014 added to function.random-bytes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214637@lists.php.net to get a copy of this message | ||
<?php
// PHP >= 7
function str_rand(int $length = 20){
$ascii_codes = range(48, 57) + range(97, 122);
$codes_lenght = (count($ascii_codes)-1);
shuffle($ascii_codes);
$string = '';
for($i = 1; $i <= $length; $i++){
$previous_char = $char ?? '';
$char = chr($ascii_codes[random_int(0, $codes_lenght)]);
while($char == $previous_char){
$char = chr($ascii_codes[random_int(0, $codes_lenght)]);
}
$string .= $char;
}
return $string;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 38.142.137.34 (proxied: 2804:d57:2ea2:5800:4515:6318:aedc:b3b1)
----
Manual Page -- http://php.net/manual/en/function.random-bytes.php
Edit -- https://master.php.net/note/edit/125014
Del: integrated -- https://master.php.net/note/delete/125014/integrated
Del: useless -- https://master.php.net/note/delete/125014/useless
Del: bad code -- https://master.php.net/note/delete/125014/bad+code
Del: spam -- https://master.php.net/note/delete/125014/spam
Del: non-english -- https://master.php.net/note/delete/125014/non-english
Del: in docs -- https://master.php.net/note/delete/125014/in+docs
Del: other reasons-- https://master.php.net/note/delete/125014
Reject -- https://master.php.net/note/reject/125014
Search -- https://master.php.net/manage/user-notes.php