note 110373 added to ref.strings
| From: | anderschwiedu at gmail dot com | Date: | Tue, 16 Oct 2012 15:23:36 +0000 |
| Subject: | note 110373 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191333@lists.php.net to get a copy of this message | ||
"kriskra at gmail dot com 03-Aug-2008 09:10" submitted a buggy random String function.
Correct would be:
<?php
function random_string($l = 10){
$c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz0123456789";
for(;$l > 0;$l--) $s .= $c{mt_rand(0,strlen($c) - 1)};
return str_shuffle($s);
}
?>
reducing strlen by one and using mt_rand instead of rand for better random numbers (no bug - just
better and faster).
----
Server IP: 69.147.83.199
Probable Submitter: 93.222.190.254
----
Manual Page -- http://www.php.net/manual/en/ref.strings.php
Edit -- https://master.php.net/note/edit/110373
Del: integrated -- https://master.php.net/note/delete/110373/integrated
Del: useless -- https://master.php.net/note/delete/110373/useless
Del: bad code -- https://master.php.net/note/delete/110373/bad+code
Del: spam -- https://master.php.net/note/delete/110373/spam
Del: non-english -- https://master.php.net/note/delete/110373/non-english
Del: in docs -- https://master.php.net/note/delete/110373/in+docs
Del: other reasons-- https://master.php.net/note/delete/110373
Reject -- https://master.php.net/note/reject/110373
Search -- https://master.php.net/manage/user-notes.php