note 69312 added to function.uniqid

From: Date: Thu, 31 Aug 2006 10:11:45 +0000
Subject: note 69312 added to function.uniqid
Groups: php.notes 
Request: Send a blank email to php-notes+get-116538@lists.php.net to get a copy of this message
I created this function to generate an extremely hard-to-predict Uniq ID (32-Byte HEX) without the worry of collisions (as with the MD5 function.) <?php function uuid() { $uuid_num = str_replace(" ","",str_replace("0.","",microtime())); $uuid_num2=explode(":",chunk_split($uuid_num,4,":")); for($uuid_i=0;$uuid_i<count($uuid_num2);$uuid_i++) $uuid_out.=dechex(rand(64,255).$uuid_num2[$uuid_i]); while(strlen($uuid_out)<32) { $uuid_out.=dechex(rand(1,16)); } return $uuid_out; } ?> The only way for a collision to happen with this function is if the function was executed at the exact microsecond AND all 20+ randomly generated numbers matched. Any thoughts, ideas, fixes, improvements? - Steve ---- Server IP: 216.194.113.175 Probable Submitter: 71.113.228.4 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.uniqid.php Edit -- https://master.php.net/note/edit/69312 Del: integrated -- https://master.php.net/note/delete/69312/integrated Del: useless -- https://master.php.net/note/delete/69312/useless Del: bad code -- https://master.php.net/note/delete/69312/bad+code Del: spam -- https://master.php.net/note/delete/69312/spam Del: non-english -- https://master.php.net/note/delete/69312/non-english Del: in docs -- https://master.php.net/note/delete/69312/in+docs Del: other reasons-- https://master.php.net/note/delete/69312 Reject -- https://master.php.net/note/reject/69312 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116538) next »