How to Generate unique random number? Can someone tell me a good method for automatically placing a unique random number in a mysql database table when a new record is created.
http://www.php.net/manual/en/function.uniqid.php
Create id as primary key auto increment
but my need is to generate random number...
http://stackoverflow.com/questions/14798640/creating-a-random-number-using-mysql
http://www.php.net/manual/en/function.com-create-guid.php
is better. Generating a random number means that you will need to check each time you generate it to ensure you haven't used it before.
This leads to race conditions
$random = (int)((rand() * rand())/rand());
you can also use that, pretty good and assures 99.9% random numbers
$random = (time()+ rand(1,1000));
Thanks All
No comments: