Am trying to use the php mt_rand() function to produce for me a unique number to be used as a unique identifier for a row in the database. Can it pick a number it had previously picked from the range 1, 1000000. My code is as follows echo mt_rand(1, 1000000);?> Thanks for your continued help
1 Answer
Yes, it will produce duplicates. It's just random, not unique. The easiest solution is to use an auto-increment column. If you don't want it to be sequential, you have a couple options. These are the two I would look at first:
rand( )to mimic a serialization of a database index.auto-incrementis the way to go