算法生成唯一的(可能是自动递增的)IDS [英] Algorithm to generate unique (possibly auto incremented) ids

查看:140
本文介绍了算法生成唯一的(可能是自动递增的)IDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成唯一的ID为我的应用程序,我正在寻找合适的算法。我想preFER这样的事 -

I need to generate unique ids for my application and I am looking for suitable algorithms. I would prefer something like this --

YYYY + MM + DD + HH + MM + SS +<随机盐GT; +<东西从preceding值&GT而得;

F.ex。 -

20100128184544ewbhk4h3b45fdg544

我想使用 SHA-256 或东西,但结果字符串应该不会太长。我可以使用 UUID 但同样,他们太长时间,他们都保证是唯一的只有一台机器。

I was thinking about using SHA-256 or something but the resultant string should not be too long. I could use UUID but again, they are too long and they are guaranteed to be unique on only one machine.

我欢迎建议,想法。我的编程语言是Java。

I would welcome suggestions, ideas. My programming language is Java.

编辑:的id不需要加密安全。我期待在简单的散列交易算法像一个由丹·伯恩斯坦等。

The ids need not be cryptographically secure. I am looking at simpler hashing algos like the one by Dan Bernstein, etc.

推荐答案

所以,我终于解决了这一点 -

So I have finally settled for this -

d = YYYYMMDDHHMMSS
hash = d + sha256(d + random_salt)[:10]

感谢大家的响应。

这篇关于算法生成唯一的(可能是自动递增的)IDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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