note 87750 deleted from function.rand by danbrown

From: Date: Fri, 19 Dec 2008 19:29:26 +0000
Subject: note 87750 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148367@lists.php.net to get a copy of this message
Note Submitter: deathshadow60 at hotmail dot com Reason: useless ---- Some of these random character string functions are just mind boggling the LACK of logic... String index lookups? Complex 'break' logic? Even simple math sillyness. $r = chr(rand(0,25)+65); Yeah, that extra addition is SO neccessary, NOT. $r=chr(rand(65,90)); better. Let's see... This would not give an even distribution as it would favor the numbers (which would make a full third of it), but would probably be faster than what we're seeing so far: function randString($length) { $result=''; for (t=0; t<$length; t++) { switch (rand(0,2)) { case 0: $result.=chr(rand(97,122)); break; case 1: $result.=chr(rand(65,90)); break; default: $result.=chr(rand(48,57)); } } return $result; }

« previous php.notes (#148367) next »