note 26860 added to function.rand

From: Date: Fri, 15 Nov 2002 03:58:04 +0000
Subject: note 26860 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-39516@lists.php.net to get a copy of this message
This seems quite randomized to me, and useful. // //Function - Psuedo-Random ASCII generator for hashing etc // srand((double)microtime()*1234567); function rand_ascii($num) { for ($i=0;$i<$num;$i++) { $randnum .= "&#" . rand(33,255) . ";"; } return $randnum; } -------------------------- I tested this 200 times over and over, throwing them into arrays and comparing each array to 199 others. I did this several times and came up with no matches. Expect to see this type of look to your printed results: …yÍ»¥éØsL€/;7õ5µ³ô!S¼uw” ãh)¹ÓՁUziF*ç½P½ýa)dì𩃠­ëzXU'ÅUŽˆÎ±rÖVÛlGl®s=Ñx Ïwk3è¸Ó“3][Ã0’LÙ/VžzÒÔڙ -- it isn't the most widly randomized thing, but trimming rand(33,255) to rand(48,57) gives you anything from 0 - 9, trimming to rand(65,90) gives you anything from A - Z, and rand(97,122) anything from a - z. (Note, the middle of 'Z' and 'a' are the following characters, in order: [\]^_` Enjoy -- http://www.php.net/manual/en/function.rand.php http://master.php.net/manage/user-notes.php?action=edit+26860 http://master.php.net/manage/user-notes.php?action=delete+26860 http://master.php.net/manage/user-notes.php?action=reject+26860

« previous php.notes (#39516) next »