![]() ![]() ![]() Calls to uuidmake that use the constants UUIDMAKEV5 or UUIDMAKEV3 (using Debian package php5-uuid available June 2010) will not work with only two variables.I could not find good documentation, so I read some source code and figured out that this would work:uuidcreate(&$v5) //uuidmake($v5, UUIDMAKEV5) uuidmake($v5, UUIDMAKEV5,$v5,$uniqid) uuidexport($v5, UUIDFMTSTR, &$v5String) Please use at your own risk. Also, it provides a means by which to reverse-engineer the time when a uniqid was generated:date('r',hexdec(substr(uniqid,0,8))) Increasingly as you go further down the string, the number becomes 'more unique' over time, with the exception of digit 9, where numeral prevalence is 0.345.f, because of the difference between 10^6 and 16^5 (this is presumably true for the remaining digits as well but much less noticeable). This is why it has microsecond precision. For the record, the underlying function to uniqid appears to be roughly as follows:$m=microtime(true) sprintf('%8x%05xn',floor($m),($m-floor($m)).1000000) In other words, first 8 hex chars = Unixtime, last 5 hex chars = microseconds. ![]() If moreentropy isTRUE, it will be 23 characters.moreentropyIf set to TRUE, uniqid will add additionalentropy (using the combined linear congruential generator) at the endof the return value, which increases the likelihood that the resultwill be unique. ParametersprefixCan be useful, for instance, if you generate identifierssimultaneously on several hosts that might happen to generate theidentifier at the same microsecond.With an empty prefix, the returned string willbe 13 characters long. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |