PHP-uniqid(“",true)与uniqid(“"")+ mt_rand() [英] PHP - uniqid("",true) versus uniqid("")+mt_rand()

查看:200
本文介绍了PHP-uniqid(“",true)与uniqid(“"")+ mt_rand()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两种生成有序但有些独特的数字的方法之间的主要区别是什么?我想使用这样的数字作为MySQL数据库中的唯一用户ID,也可以作为对密码进行加盐处理.

What are the key differences between these two approaches to generate sequential-but-somewhat-unique numbers? I want to use such a number as a unique user ID inside a MySQL db, and also as a salt to salt a password.

我的理解是,出于聚类和索引的原因,这些ID应该是顺序的(我意识到,在某些情况下,随机字符串将使在同一微秒中出现的两个条目成为非顺序的,但希望可以忽略不计.)

My understanding is that for clustering and indexing reasons those IDs should be sequential (I realize that in some cases the random string will make two entries that occurred in the same microsecond non sequential, but hopefully this is negligible.)

推荐答案

(抓取此信息,错误信息,对不起)

(scratch this, wrong info, sorry)

是的,正如Gumbo指出的那样,它不是哈希值,而是一个微秒分辨率的递增计时器值,可以选择将其与一个随机数连接.因此,这些值仍然不是连续的,但至少是稳定的. 两种方法之间的差异将很小.

So yes, as Gumbo pointed out, it's not a hash but indeed a microsecond resolution increasing timer value, optionally concatenated with a random number. So, the values are still not sequential, but at least steady. The difference between the two approaches would then be very small.

这个仍然成立:如果您需要唯一的顺序数字,并且您使用的是MySQL,请使用自动递增字段,它们会自动执行此操作.

This one still holds: If you need unique sequential numbers, and you use MySQL, use an auto increment field, they do just that.

这篇关于PHP-uniqid(“",true)与uniqid(“"")+ mt_rand()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆