MD5 uuid collision?
I'm dealing with image uploads and I'd like some suggestions on naming files and folders. Currently, I'开发者_JAVA百科m generating a file name using the following:
md5( microtime() ) . $this->user_id
That outputs something like:
e89ae1857038d0e5d0f8092e6c5390b91
I then take the first 3 characters of that file name to generate the folders. Which will be something like:
/e/8/9
So it ends up being:
/e/8/9/e89ae1857038d0e5d0f8092e6c5390b91
I'm using the md5 so that it somewhat evenly distributes the files across the folders. Is that a good uuid? Is there a chance for collision?
Thanks in advance.
With any hash, there is a chance for collision. If you think about it, a hash takes an infinite number of inputs and turns it into a finite number of outputs.
But, for all practical (non-academic) implications, there is no such thing as a collision. 2^128 is such a huge number it will never happen before even the heat death of the universe.
精彩评论