PHP: why uniqid returned value is only 13 digits long
- by Marco Demaio
uniqid() function returns a 13 digits long hexadecimal number. According to the spec in php.net site, the function uses microtime to generate the unique value.
But microtime returns numbers in string format as the following one:
"0.70352700 12689396875"
which are basically the microseconds and the seconds elapsed since 1970.
This is a 9+11 digits decimal number.
Converting a 20 decimal number into hex would result in a 16 digits hexadecimal NOT a 13 digits one.
I also thought to take out the "0." part that seem to never change, and the last two digits of the microsec part that seem to remain always "00". Doing this the decimal number would be only 9+11-3 digits long, but still a decimal number of 17 digits when converted into hex would result in 14 digits hexadecimal number NOT 13.
You probably think I'm crazy in asking such a thing, but I'm concerned about using uniqid, unique values are important to be unique, a duplicated value could screw up an entire application.