Reputation: 9
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
Upvotes: 0
Views: 150
Reputation: 7005
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:
https://github.com/ramsey/uuid
http://php.net/manual/en/function.uniqid.php
Upvotes: 4