note 95414 added to function.shuffle

From: Date: Sat, 02 Jan 2010 02:59:46 +0000
Subject: note 95414 added to function.shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-164531@lists.php.net to get a copy of this message
Here is a quick function I wrote that generates a random password and uses shuffle() to easily shuffle the order. public function randPass($upper = 3, $lower = 3, $numeric = 3, $other = 2) { //we need these vars to create a password string $passOrder = Array(); $passWord = ''; //generate the contents of the password for ($i = 0; $i < $upper; $i++) { $passOrder[] = chr(rand(65, 90)); } for ($i = 0; $i < $lower; $i++) { $passOrder[] = chr(rand(97, 122)); } for ($i = 0; $i < $numeric; $i++) { $passOrder[] = chr(rand(48, 57)); } for ($i = 0; $i < $other; $i++) { $passOrder[] = chr(rand(33, 47)); } //randomize the order of characters shuffle($passOrder); //concatenate into a string foreach ($passOrder as $char) { $passWord .= $char; } //we're done return $passWord; } ---- Server IP: 192.41.40.227 Probable Submitter: 24.119.206.248 ---- Manual Page -- http://www.php.net/manual/en/function.shuffle.php Edit -- https://master.php.net/note/edit/95414 Del: integrated -- https://master.php.net/note/delete/95414/integrated Del: useless -- https://master.php.net/note/delete/95414/useless Del: bad code -- https://master.php.net/note/delete/95414/bad+code Del: spam -- https://master.php.net/note/delete/95414/spam Del: non-english -- https://master.php.net/note/delete/95414/non-english Del: in docs -- https://master.php.net/note/delete/95414/in+docs Del: other reasons-- https://master.php.net/note/delete/95414 Reject -- https://master.php.net/note/reject/95414 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164531) next »