note 106004 added to function.rand

From: Date: Sun, 02 Oct 2011 03:34:02 +0000
Subject: note 106004 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-183582@lists.php.net to get a copy of this message
I couldn't find a suitable random alpha-numeric generator function so I rolled my own. It gives a random number in base 36 (0-9, a-z) to a given length. function randomAlphaNum($length){ $rangeMin = pow(36, $length-1); //smallest number to give length digits in base 36 $rangeMax = pow(36, $length)-1; //largest number to give length digits in base 36 $base10Rand = mt_rand($rangeMin, $rangeMax); //get the random number $newRand = base_convert($base10Rand, 10, 36); //convert it return $newRand; //spit it out } hopefully helps someone ---- Server IP: 202.89.58.1 Probable Submitter: 125.236.233.104 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/106004 Del: integrated -- https://master.php.net/note/delete/106004/integrated Del: useless -- https://master.php.net/note/delete/106004/useless Del: bad code -- https://master.php.net/note/delete/106004/bad+code Del: spam -- https://master.php.net/note/delete/106004/spam Del: non-english -- https://master.php.net/note/delete/106004/non-english Del: in docs -- https://master.php.net/note/delete/106004/in+docs Del: other reasons-- https://master.php.net/note/delete/106004 Reject -- https://master.php.net/note/reject/106004 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183582) next »