随机数生成器如何工作? [英] How does a random number generator work?

查看:108
本文介绍了随机数生成器如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随机数生成器如何工作? (例如,在C/C ++ Java中)

How do random number generator works? (for example in C/C++ Java)

如何编写自己的随机数生成器? (例如,在C/C ++ Java中)

How can I write my own random number generator? (for example in C/C++ Java)

推荐答案

也有此算法:

哦,更重要的是:

随机数生成器使用数学公式将一组数字转移到另一个数字.例如,如果您采用一个常数N和另一个数字n_0,然后采用n mod N的值(取模运算符),则会得到一个新的数字n_1,它看起来像与n_0无关.现在,用n_1重复相同的过程,您将得到另一个数字.您在这里拥有的是(VERY BAD)生成器,看似随机数.

Random number generators use mathematical formulas that transfer set of numbers to another one. If, for example, you take a constant number N and another number n_0, and then take the value of n mod N (the modulo operator), you will get a new number n_1, which looks as it if is unrelated to n_0. Now, repeat the same process with n_1 and you'll get another number. What you have here is a (VERY BAD) generator of seemingly random numbers.

请记住,我在这里描述的方法是一种玩具方法,不应用于任何严重的事情.但是,它确实说明了一般原理.

Remember, the method I've described here is a toy method that should not be used for anything serious. It does, however, illustrate the general principle.

还请注意:

如果所有因rand错误而导致结果令人怀疑的科学论文都将从图书馆的书架上消失了,那么每个书架上的空隙将与拳头一样大.

If all scientific papers whose results are in doubt because of bad rands were to disappear from library shelves, there would be a gap on each shelf about as big as your fist.

(由数字食谱的第7章解释).对于使用随机数生成器进行任何重要工作的任何人来说,这都是必读的文本.

(paraphrased from chapter 7 of Numerical recipes). This is a must-read text for anyone who uses random number generators for any serious work.

这篇关于随机数生成器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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