note 61934 added to function.mt-rand

From: Date: Wed, 15 Feb 2006 13:38:12 +0000
Subject: note 61934 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-103771@lists.php.net to get a copy of this message
I know a bunch of you have posted little snippets for random number generation, but here's a nifty (in my opinion) little thing I just wrote to create a 10 digit code with hyphens in it. It also negates the use of 0, O, 1, and I, to avoid confusion. I am ALWAYS willing to accept input so if any of you has suggestions to streamline the code, please let me know. <?php function GetID($x){ $characters = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", "8", "9"); shuffle($characters); for (; strlen($ReqID)<$x;){ $ReqID .= $characters[mt_rand(0, count($characters))]; } return $ReqID; } $ReqID .= GetID(3); $ReqID .= "-"; $ReqID .= GetID(4); $ReqID .= "-"; $ReqID .= GetID(3); echo $ReqID ?> ---- Server IP: 66.207.199.35 Probable Submitter: 24.86.102.199 ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61934 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61934&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61934&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103771) next »