note 111004 deleted from function.rand by danbrown

From: Date: Thu, 17 Jan 2013 15:24:13 +0000
Subject: note 111004 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193143@lists.php.net to get a copy of this message
Note Submitter: kokuswolf at pireality dot de ---- In addition to the slightly outdated two posts below here some actual results with PHP 5.4.10. Unix rand() inferiority (171.08 ms): Array ( [0] => 5 [1] => 10 [2] => 8 [3] => 9 [4] => 9 [5] => 13 [6] => 13 [7] => 5 [8] => 15 [9] => 10 [10] => 10 ) Unix mt_rand() inferiority (170.96 ms): Array ( [0] => 6 [1] => 8 [2] => 14 [3] => 12 [4] => 12 [5] => 8 [6] => 9 [7] => 10 [8] => 9 [9] => 12 [10] => 11 ) And some shorter and quicker way of generating random chars: <?php function randchars($num, $charset = 'abcdefghijkmnopqrstuvwxyz0123456789'){ $charrange = strlen($charset)-1; $string = ''; for($i=1; $i<=$num; $i++){ $string .= $charset[mt_rand(0, $charrange)]; } return $string; } echo randchars(12); // 0t89r9y64oqv echo randchars(8, 'abcdef'); // afeddcad ?>

« previous php.notes (#193143) next »