note 110373 deleted from ref.strings by googleguy

From: Date: Tue, 16 Oct 2012 16:32:14 +0000
Subject: note 110373 deleted from ref.strings by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191336@lists.php.net to get a copy of this message
Note Submitter: anderschwiedu at gmail dot com ---- "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).

« previous php.notes (#191336) next »