关于随机发生器的问题 [英] question about random generator

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

问题描述

大家好


我是这个论坛的新手和c编程语言。

如果我明白了,C中的random()函数返回遵循

均匀分布U(0,1)的数字。有人可以知道如何生成一组遵循正态分布N(0,1)的随机数吗?我在运行AIX的power4机器上发现了



感谢您的帮助

Hi all

I am new to this forum and to the c programming language.
If I understand, the random() function in C return numbers that follow a
uniform distribution U(0,1). Can somebody know how to generate a set of
random number that follow a normal distribution N(0,1) ? I am develloping
on power4 machine running AIX.

Thank you for your help

推荐答案

Marc Dansereau写道:
Marc Dansereau wrote:
大家好

我是这个论坛和c编程语言的新手。
如果我理解,随机C中的()函数返回遵循均匀分布U(0,1)的数字。


C中没有标准函数,叫做random()。标准的

伪随机函数是rand()。它返回的值不是U(0,1)。

它将

范围0中的伪随机数(未指定分布)返回到RAND_MAX,其中RAND_MAX必须至少32767.

有人知道如何生成一组遵循正态分布N(0,1)的随机数吗?
Hi all

I am new to this forum and to the c programming language.
If I understand, the random() function in C return numbers that follow a
uniform distribution U(0,1).
There is no standard function in C called random(). The standard
pseudo-random function is rand(). The values it returns are not U(0,1).
It returns pseudo-random numbers (no distribution specified) in the
range 0 to RAND_MAX, where RAND_MAX must be at least 32767.
Can somebody know how to generate a set of
random number that follow a normal distribution N(0,1) ?




您应该*在发布问题之前*始终*检查新闻组的常见问题解答。

随机数问题的核心列表是13.15到13.20。特别是

,请参阅问题13.20如何生成具有

普通或高斯分布的随机数?

< http ://www.eskimo.com/~scs/C-faq/q13.20.html>



You should *always* check a newsgroup''s FAQ before posting a question.
The core list of random-number questions are 13.15 through 13.20. In
particular, see question 13.20 "How can I generate random numbers with a
normal or Gaussian distribution?"
<http://www.eskimo.com/~scs/C-faq/q13.20.html>


Marc Dansereau写道:
Marc Dansereau wrote:
大家好

我是这个论坛和c编程语言的新手。
如果我理解,C中的random()函数返回的数字跟随
均匀分布U(0,1)。有人可以知道如何生成一组遵循正态分布N(0,1)的随机数吗?我正在开发运行AIX的power4机器上。
Hi all

I am new to this forum and to the c programming language.
If I understand, the random() function in C return numbers that follow a
uniform distribution U(0,1). Can somebody know how to generate a set of
random number that follow a normal distribution N(0,1) ? I am develloping
on power4 machine running AIX.




首先,标准C中没有random()函数
图书馆。如果你的系统提供这样的功能,它是一个额外的,额外的奖金,C的附加扩展,而不是C本身的一部分。


兰特()函数生成均匀分布的

整数,范围为0< = rand()< = RAND_MAX< = 32767.

从这个来源,你可以生成浮动-b
中的点数0< = y< 1:`rand()/(RAND_MAX + 1.0)''。注意

这些值可能只有15位''

" precision;"如果你需要更多,你可能需要结合

多个rand()调用的结果,如


(rand()+(rand()/ (RAND_MAX + 1.0)))/(RAND_MAX + 1.0)


(小学生注意:上述表达式中的歧义

可能被认为是一种好处,在这种情况下。)


现在你已经在(0,1)中得到了(近似)统一的

分布数字的来源有几种方法可以生成

正态分布数字。最简单的编程肯定是极地方法。 (谷歌是你的朋友);更快的方法如果你愿意做额外的工作,就会存在
。参见Knuth

计算机程序设计的艺术,第二卷:研究数学

算法。 (事实上​​,无论如何看到Knuth:标准使得

几乎不能保证

rand()函数的统计优点,如果你是做高精度的工作你需要用b / b
代替你的特征来源。$


-

Eric Sosman
es ***** @ acm-dot-org.inva lid



First, there is no random() function in the Standard C
library. If your system offers such a function, it is an
extra, bonus, add-on extension to C, not part of C itself.

The rand() function generates uniformly distributed
integers in the range 0 <= rand() <= RAND_MAX <= 32767.
From this source, you can generate floating-point numbers in
the range 0 <= y < 1: `rand() / (RAND_MAX + 1.0)''. Note
that these values may have as little as fifteen bits''
"precision;" if you need more, you may need to combine
the results of multiple rand() calls as in

(rand() + (rand() / (RAND_MAX + 1.0))) / (RAND_MAX + 1.0)

(Pedants take note: The ambiguity in the above expression
may be considered a benefit, under the circumstances.)

Now that you''ve got a source of (approximately) uniformly-
distributed numbers in [0,1), there are several ways to produce
normally-distributed numbers. The easiest to program is surely
the "polar method" (Google is your friend); faster methods
exist if you''re willing to do the extra work. See Knuth
"The Art of Computer Programming, Volume II: Seminumerical
Algorithms." (In fact, see Knuth anyhow: the Standard makes
almost no guarantees about the statistical "goodness" of the
rand() function, and if you''re doing high-precision work you
should substitute a source whose characteristics you can
count on.)

--
Eric Sosman
es*****@acm-dot-org.invalid


Martin Ambuhl写道:
Martin Ambuhl wrote:
Marc Dansereau写道:
Marc Dansereau wrote:
...
有人知道如何生成一组遵循正态分布N(0,1)的随机数吗?
...
Can somebody know how to generate a set of
random number that follow a normal distribution N(0,1) ?



你应该*总是*检查新闻组的'发布问题之前的常见问题。
随机数问题的核心列表是13.15到13.20。特别是,请参阅问题13.20如何生成具有正常或高斯分布的随机数?
< http://www.eskimo.com/~scs/ C-faq / q13.20.html>



You should *always* check a newsgroup''s FAQ before posting a question.
The core list of random-number questions are 13.15 through 13.20. In
particular, see question 13.20 "How can I generate random numbers with a
normal or Gaussian distribution?"
<http://www.eskimo.com/~scs/C-faq/q13.20.html>




也许值得一看...

http://benpfaff.org/writings/clc/random.html
< br $> b $ b -

彼得



It might also be worth looking at...

http://benpfaff.org/writings/clc/random.html

--
Peter


这篇关于关于随机发生器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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