note 111004 added to function.rand

From: Date: Fri, 04 Jan 2013 14:02:35 +0000
Subject: note 111004 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-192763@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 69.147.83.199 Probable Submitter: 217.91.162.102 ---- Manual Page -- http://php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/111004 Del: integrated -- https://master.php.net/note/delete/111004/integrated Del: useless -- https://master.php.net/note/delete/111004/useless Del: bad code -- https://master.php.net/note/delete/111004/bad+code Del: spam -- https://master.php.net/note/delete/111004/spam Del: non-english -- https://master.php.net/note/delete/111004/non-english Del: in docs -- https://master.php.net/note/delete/111004/in+docs Del: other reasons-- https://master.php.net/note/delete/111004 Reject -- https://master.php.net/note/reject/111004 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192763) next »