如何生成"随机"而且还与QUOT;独特的"号码? [英] How to generate "random" but also "unique" numbers?
问题描述
如何产生的随机数。?如何语言如Java等产生随机数,它被特别是如何为GUID的完成。?我发现,像Pseudorandomnumber生成算法使用的初始值。
但我需要创建一个随机数的程序,其中一些曾经发生绝不应该重复,即使在系统重新启动等。我想,我需要存储值的任何地方,这样我可以检查一些重复或没有,但这样的例子不胜枚举超过这个极限,将是太复杂了。
第一:如果数字是保证绝不重复,这不是很随意
二:有很多的 PRNG算法
更新:
第三:有一个的IETF RFC的UUID (什么MS调用的GUID),但你应该认识到,(U | G)的UID的不的密码安全,如果这是你所关心
<。 p>更新2:
如果要真正地在生产中使用的代码是这样的(不只是为自己的熏陶)请使用预先存在的库。这是何许那几乎肯定会在这微妙的错误,如果你从来没有这么做过(或者即使你有)代码
更新3:
How are random numbers generated.? How do languages such as java etc generate random numbers, especially how it is done for GUIDs.? i found that algorithms like Pseudorandomnumber generator uses initial values.
But i need to create a random number program, in which a number once occurred should never repeats even if the system is restarted etc. I thought that i need to store the values anywhere so that i can check if the number repeats or not, but it will be too complex when the list goes beyond limits.?
First: If the number is guaranteed to never repeat, it's not very random.
Second: There are lots of PRNG algorithms.
UPDATE:
Third: There's an IETF RFC for UUIDs (what MS calls GUIDs), but you should recognize that (U|G)UIDs are not cryptographically secure, if that is a concern for you.
UPDATE 2:
If you want to actually use something like this in production code (not just for your own edification) please use a pre-existing library. This is the sort of code that is almost guaranteed to have subtle bugs in it if you've never done it before (or even if you have).
UPDATE 3:
Here's the docs for .NET's GUID
这篇关于如何生成"随机"而且还与QUOT;独特的"号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!