真随机数
Truly random numbers
我这里有两个问题:
请解释一下真随机数的含义。看了很多文章还是没看懂。
请用任何语言向我解释 Rand() 函数背后的代码,最好是 c++
- 真正的随机数是由物理随机事件(自然界不可预测的事件)决定的。例如(原子的放射性衰变、大气噪声等)。之所以如此,是因为计算机本身并没有真正随机的能力,但大自然是。因此,如果计算机测量自然界中的某个随机值,那么该数字是 "truly random," 但伪是计算机生成种子的地方(C++ 使用 time 生成种子)和随机数似乎是随机的,但可以预测。
"The computer uses a function to calculate random numbers. That means: having the same seed, we get the same row of random numbers every time. Therefore pseudo random numbers." – 拉尔夫·M·里肯巴赫
- C++ 使用时间,自 1970 年 1 月 1 日午夜以来的秒数。因此,当您告诉计算机生成一个随机数时,它需要自 1970 年 1 月 1 日以来的秒数(一个非常大的数字,种子) ,通过算法发送,然后根据你指定的范围进行切分。
This causes the computer to read its clock to obtain the value for the seed automatically.
Function time returns the number of seconds that have passed since midnight on January 1, 1970. This value is converted to an unsigned integer and used as the seed to the random number generator.
这当然是一种简化,更多内容可以在线阅读。以下是参考资料。
参考文献:
简短摘要:
真正的随机数是在任何情况下都无法计算的数字是由某个事件产生的,而Rand()
函数计算的随机数是计算出来的.
有多种方法可以计算这样的数字,有些方法比其他方法更复杂。
有关它在(objective- 在这种情况下)C 中如何工作的更多详细信息,请参阅 this question。
我这里有两个问题:
请解释一下真随机数的含义。看了很多文章还是没看懂。
请用任何语言向我解释 Rand() 函数背后的代码,最好是 c++
- 真正的随机数是由物理随机事件(自然界不可预测的事件)决定的。例如(原子的放射性衰变、大气噪声等)。之所以如此,是因为计算机本身并没有真正随机的能力,但大自然是。因此,如果计算机测量自然界中的某个随机值,那么该数字是 "truly random," 但伪是计算机生成种子的地方(C++ 使用 time 生成种子)和随机数似乎是随机的,但可以预测。
"The computer uses a function to calculate random numbers. That means: having the same seed, we get the same row of random numbers every time. Therefore pseudo random numbers." – 拉尔夫·M·里肯巴赫
- C++ 使用时间,自 1970 年 1 月 1 日午夜以来的秒数。因此,当您告诉计算机生成一个随机数时,它需要自 1970 年 1 月 1 日以来的秒数(一个非常大的数字,种子) ,通过算法发送,然后根据你指定的范围进行切分。
This causes the computer to read its clock to obtain the value for the seed automatically. Function time returns the number of seconds that have passed since midnight on January 1, 1970. This value is converted to an unsigned integer and used as the seed to the random number generator.
这当然是一种简化,更多内容可以在线阅读。以下是参考资料。
参考文献:
简短摘要:
真正的随机数是在任何情况下都无法计算的数字是由某个事件产生的,而Rand()
函数计算的随机数是计算出来的.
有多种方法可以计算这样的数字,有些方法比其他方法更复杂。
有关它在(objective- 在这种情况下)C 中如何工作的更多详细信息,请参阅 this question。