This question isn’t really a problem looking for a solution, it’s more just a matter of simple curiosity. The PHP uniqid function has a more entropy flag, to make the output “more unique”. This got me wondering, just how likely is it for this function to produce the same result more than once when more_entropy is true, versus when it isn’t. In other words, how unique is uniqid when more_entropy is enabled, versus when it is disabled? Are there any drawbacks to having more_entropy enabled all the time?
Share
Update, March 2014:
Firstly, it is important to note that
uniqidis a bit of a misnomer as it doesnt guarantee a unique ID.Per the PHP documentation:
And
Setting more-entropy to true generates a more unique value, however the execution time is longer (though to a tiny degree), according to the docs:
Note the line
increases the likelihood that the result will be uniqueand not that is will guarantee uniqueness.You can ‘endlessly’ strive for uniqueness, up to a point, and enhance using any number of encryption routines, adding salts and the like- it depends on the purpose.
I’d recommend looking at the comments on the main PHP topic, notably:
http://www.php.net/manual/en/function.uniqid.php#96898
http://www.php.net/manual/en/function.uniqid.php#96549
http://www.php.net/manual/en/function.uniqid.php#95001
What I’d recommend is working out why you need uniqueness, is it for security (i.e. to add to an encryption/scrambling routine)? Also, How unique does it need to be? Finally, look at the speed consideration. Suitability will change with the underlying considerations.