note 90509 added to function.rand

From: Date: Sat, 25 Apr 2009 17:13:39 +0000
Subject: note 90509 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-153766@lists.php.net to get a copy of this message
A nice function to generate a random string, using any character: function generateRandStr($length){ $randstr = ""; for($i=0; $i<$length; $i++){ $randnum = mt_rand(0,61); if($randnum < 10){ $randstr .= chr($randnum+48); }else if($randnum < 36){ $randstr .= chr($randnum+55); }else{ $randstr .= chr($randnum+61); } } return $randstr; } Simply use: generateRandStr(10); Sample output: $%29zon(4f ---- Server IP: 130.206.1.5 Probable Submitter: 88.18.14.14 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/90509 Del: integrated -- https://master.php.net/note/delete/90509/integrated Del: useless -- https://master.php.net/note/delete/90509/useless Del: bad code -- https://master.php.net/note/delete/90509/bad+code Del: spam -- https://master.php.net/note/delete/90509/spam Del: non-english -- https://master.php.net/note/delete/90509/non-english Del: in docs -- https://master.php.net/note/delete/90509/in+docs Del: other reasons-- https://master.php.net/note/delete/90509 Reject -- https://master.php.net/note/reject/90509 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153766) next »