note 78462 added to function.microtime

From: Date: Fri, 12 Oct 2007 23:35:52 +0000
Subject: note 78462 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-131354@lists.php.net to get a copy of this message
kayode's implementation of randomString() generates predictable data (digit,letter,digit,letter,digit,...) and thus shouldn't be used for anything sensitive like transaction ids. See uniqid() for this kind of functionality. If you insist on rolling your own, you'd could do something like: <? function rstr($len) { $i = 0; $str = ""; while ($i++ < $len) $str .= chr(rand(33,126)); return $str; } echo rstr(16); // Outputs: q$lUY*Q1"1U%>+wi ?> This generates a string of chars from the printable range of ascii chars. To get a random hex-string, do something like: <? function rstr($len) { $i = 0; $str = ""; while ($i++ < $len) $str .= dechex(rand(0,15)); return $str; } echo rstr(16); // Outputs: 4f1f8c95514db8dd ?> ---- Server IP: 62.73.196.231 Probable Submitter: 193.91.135.250 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/78462 Del: integrated -- https://master.php.net/note/delete/78462/integrated Del: useless -- https://master.php.net/note/delete/78462/useless Del: bad code -- https://master.php.net/note/delete/78462/bad+code Del: spam -- https://master.php.net/note/delete/78462/spam Del: non-english -- https://master.php.net/note/delete/78462/non-english Del: in docs -- https://master.php.net/note/delete/78462/in+docs Del: other reasons-- https://master.php.net/note/delete/78462 Reject -- https://master.php.net/note/reject/78462 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131354) next »