Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

关于php的uniqid生成唯一ID的疑问

如下图,md5不是依赖输入么?为什么加md5就能绝对唯一了?求大神解答!

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

终于自己找到原因了,md5(uniqid(mt_rand(), true)),这个其实就是双随机+时间戳生成的唯一id,基本上,这个算法在很大程度上能保证唯一性了,但确实存在碰撞的可能。
image.png

结论:
1、md5(uniqid(mt_rand(), true)) 理论上确实存在碰撞可能
2、小公司放心用,大厂就谨慎使用


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...