note 54534 added to function.mt-rand

From: Date: Thu, 07 Jul 2005 07:40:12 +0000
Subject: note 54534 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-91574@lists.php.net to get a copy of this message
if you want an absolute unique id try this, md5(microtime().data("r").rand(10000, 32000)); this way its almost impossible to generate the same hash again since the microtime unixtimestamp, the rfc date and a random number of 5 digits make the changes of having the same input to create the hash about 22000 posiblities per milisecond. so if you can generete 22000 diffrent hashes per milisecond you might have a double, else you have to wait another 128 years orso before the same combination can be generated. i have run a test om my pc with the possibilties of generating the same random and with 5 digits it needed almost 5min before the same number would come again. this type of hashing can be fairly safe for genereting a secure session id to keep track that your still talking to the same client. i use this in some websites and the performance is barley affected, although i find the performance diffrence between rand and mt_rand almost none. use normal rand when you can and mt_rand only when speed is a must. one small note to the documentation team, don't know if here is the right place to ask, but i might be an idea to place the php version when a function became supported next to the function name in the listings, now i have to check each function to see if i can use it in my php version. just my 2 eurocents, ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54534 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54534&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54534&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54534&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54534&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54534&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54534&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54534&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91574) next »