How to Generate unique random number in PHP

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.

Create id as primary key auto increment

but my need is to generate random number...
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

Post a Comment