随机数字无法满足? [英] Random numbers something insatiable ?

查看:70
本文介绍了随机数字无法满足?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我当我在rand()时CPU内发生了什么吗?

我在哪里可以找到真正的rand函数?我听说

,C / C ++中的rand()不是很好但是为什么它不是好的,

他们骗我了吗?

他们为什么要这样做?


谢谢

MnConly

Can you tell me what happens inside CPU when I rand() ?
Where can I find the true rand function implemented ? I have heard
that rand() in C/C++ is n''t a good one but why it isn''t a good one,
are they lying to me ?
Why do they have to do that ?

Thank you
MnConly

推荐答案

MConly写道:
你能告诉我当rand()时CPU内发生了什么?


您应该能够在C运行时库的

源代码中看到此函数的实现。它现在附带几乎每个

编译器。

我在哪里可以找到实现的真正的rand函数?


来源。 使用the Source,Luke!

我听说过C / C ++中的rand()不是很好但是为什么它不是好的,
他们骗我吗?


谁?

为什么他们必须这样做?
Can you tell me what happens inside CPU when I rand() ?
You should be able to see the implementation of this function in the
source code for the C run-time library. It ships with almost every
compiler nowadays.
Where can I find the true rand function implemented ?
In the source. "Use the Source, Luke!"
I have heard
that rand() in C/C++ is n''t a good one but why it isn''t a good one,
are they lying to me ?
Who?
Why do they have to do that ?




谁?



Who?


MConly写道:

你能告诉我当rand()时CPU内发生了什么?


没什么特别的。它只是一个被执行的公式。

我在哪里可以找到实现的真正的rand函数?


没有。

语言标准没有具体说明使用哪种公式。

但是通常的rand()实现使用一个非常简单的公式。

我听说过C / C ++中的rand()不是很好但是为什么它不是好的,


首先,您需要了解计算机中的随机性

只是一个统计属性。这意味着:给予例如。 1000个这样的数字,

可以使用统计测试来检查这些数字是否具有随机性的统计特性

统计特性(其中没有人真正知道

什么随机性真的意味着)。这样做时,人们可能会注意到

rand()的结果并没有通过所有这些测试。特别是很多

rand()的实现在数字的低位数b / b中都不是那么好。因此,如果使用rand()

的结果并清除所有数字的高位(对于某些定义

''high order''),它可能是结果中出现了一些模式

序列。如果有一个模式,那么可以通过了解过去的历史来预测下一个随机数的结果



他们在骗我吗?
为什么他们必须这样做?

Can you tell me what happens inside CPU when I rand() ?
Nothing special. It is just a formula that gets executed.
Where can I find the true rand function implemented ?
There is none.
The language standards don''t specify which formula to use.
But usual rand() implementations use a very simple formula.
I have heard
that rand() in C/C++ is n''t a good one but why it isn''t a good one,
First of all you need to understand that ''randomness'' in a computer
is just a statistical property. That means: given eg. 1000 such numbers,
one can use a statistical test to check if those numbers have the
statistical properties of randomness (whereby nobody really knows
what randomness really means). When doing so, one might notice that
the result of rand() doesn''t pass all those tests. Especially many
implementations of rand() are known to be not that good in the low
order bits of the numbers. So if one uses the results of rand()
and clears the high order bits of all numbers (for some definition
of ''high order'') it may be that some pattern shows up in the result
sequence. And if there is a pattern, then one can predict the outcome
of the next random number by knowing the past history.
are they lying to me ?
Why do they have to do that ?




因为为$ / b
生成序列提供好的公式并不是一件小事。随机数字

*快速

*质量好


重点是:

有点小心,rand()足以做大部分的自制编程。如果你需要为赌场进行编程,那么需要更好的随机数生成器,你已经有了实现更好的随机数生成器的知识。


-

Karl Heinz Buchegger
kb **** **@gascad.at


Victor Bazarov写道:
Victor Bazarov wrote:
that C / C ++中的rand()不是很好但是为什么它不是好的,
它们对我说谎吗?
that rand() in C/C++ is n''t a good one but why it isn''t a good one,
are they lying to me ?



谁?


Who?

为什么他们必须这样做?
Why do they have to do that ?



谁?


Who?




他们。 ..你知道,这些混蛋!



They... You know, the bastards!


这篇关于随机数字无法满足?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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