note 78462 deleted from function.microtime by tularis

From: Date: Sun, 22 Jun 2008 12:05:12 +0000
Subject: note 78462 deleted from function.microtime by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140664@lists.php.net to get a copy of this message
Note Submitter: Elsand ---- 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 ?>

« previous php.notes (#140664) next »