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

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

问题描述

随机数生成器是如何工作的?(例如在 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 重复相同的过程,您将得到另一个数字.你在这里拥有的是一个(非常糟糕的)看似随机数的生成器.

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天全站免登陆