php - Is it wrong to use a hash for a unique ID? -


i want use unique id generated php in database table never have more 10,000 records. don't want time of creation visible or use purely numeric value using:

sha1(uniqid(mt_rand(), true)) 

is wrong use hash unique id? don't hashes lead collisions or chances remote should not considered in case?

a further point: if number of characters hashed less number of characters in sha1 hash, won't unique?

if have 2 keys have theoretical best case scenario of 1 in 2 ^ x probability of collision, x number of bits in hashing algorithm. best case cause input ascii doesn't utilize full charset, plus hashing functions doesn't distribute perfectly, collide more theoretical max in real life.

to answer final question:

a further point: if number of characters hashed less number of characters in sha1 hash, won't unique?

yeah that's true sorta. have problem of generating unique keys of size. easiest way checksum, choose large enough digest collision space small enough comfort.

as @wayne suggests, used approach concatenate microtime() random salt (and base64_encode raise entropy).


Comments