note 84995 added to function.rand

From: Date: Fri, 08 Aug 2008 22:48:35 +0000
Subject: note 84995 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-143318@lists.php.net to get a copy of this message
A quick correction on my last post There is a way to make my method even faster After reading through the older comments on this page, i noticed the post by relsqui at armory dot com on 21-Jan-2005 02:23 about using bitwise operations This makes my function even faster Instead of a process time of 0.00065 average, using bitwise operations has dropped this down to 0.00051 average. This is based on creating a 50 character password to be more realistic, creating a 10 character password takes 0.000013269286 on average (average gained from 1,000,000 executions) function pass_gen($pass_length) { $str = '012345679abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $pass = ''; $str_len = strlen($str) -1; for($i=0; $i < $pass_length; $i++) { $rand = mt_rand()&$str_len; $pass .=$str[$rand]; } return $pass; } ---- Server IP: 69.147.83.197 Probable Submitter: 79.76.108.27 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/84995 Del: integrated -- https://master.php.net/note/delete/84995/integrated Del: useless -- https://master.php.net/note/delete/84995/useless Del: bad code -- https://master.php.net/note/delete/84995/bad+code Del: spam -- https://master.php.net/note/delete/84995/spam Del: non-english -- https://master.php.net/note/delete/84995/non-english Del: in docs -- https://master.php.net/note/delete/84995/in+docs Del: other reasons-- https://master.php.net/note/delete/84995 Reject -- https://master.php.net/note/reject/84995 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143318) next »