多个随机数 [英] multiple random number

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

问题描述

假设我有一个函数rand()可以生成一个随机的整数

在0到100之间的数字。假设rand()非常昂贵。什么

是在0和

100之间产生10个不同随机数的最快方法? (只调用rand()10次......)


谢谢,


qq

Suppose I have a function rand() that can generate one integer random
number between 0 and 100. Suppose also rand() is very expensive. What
is the fastest way to generate 10 different random number between 0 and
100? (call rand() only 10 times...)

Thanks,

qq

推荐答案

qu******@yahoo.com 写道:
qu******@yahoo.com writes:
假设我有一个函数rand(),可以生成0到100之间的一个随机整数。假设rand()非常昂贵。什么
是在0和
100之间生成10个不同随机数的最快方法? (只调用rand()10次......)
Suppose I have a function rand() that can generate one integer random
number between 0 and 100. Suppose also rand() is very expensive. What
is the fastest way to generate 10 different random number between 0 and
100? (call rand() only 10 times...)




最快的方法可能是使用

rand以外的函数( )做一代。除此之外,我甚至没有看到你问的问题。在没有更多信息的情况下,只有少数合理的方法来编写10迭代循环。

-

Ben Pfaff

电子邮件: bl*@cs.stanford.edu

web: http://benpfaff.org


qu ****** @ yahoo.com 写道:
假设我有一个函数rand()这可以生成0到100之间的一个整数随机数。假设rand()非常昂贵。什么
是在0和
100之间生成10个不同随机数的最快方法? (只调用rand()10次......)
Suppose I have a function rand() that can generate one integer random
number between 0 and 100. Suppose also rand() is very expensive. What
is the fastest way to generate 10 different random number between 0 and
100? (call rand() only 10 times...)



使用不同的rand()并不昂贵,可能会占用

帐户丢失随机性。


一个基于线性同余的随机数发生器很快,如果写好b $ b,那么随机足够。对于大多数目的。如果这是一个优秀的随机数源,你可以用

来自rand()的一个数字播种它。


参见FAQ的问题13.15 NG。你可能也会变得更好

在一个新闻组中的回复,这不是特定于C的,比如comp.programming

和sci.crypt.random-numbers(但是阅读他们的常见问题首先,当

合适时,我还没有)。


(伪) - 随机数生成是自己在计算机领域的研究

编程。


S.


Use a different rand() that is not expensive, possibly taking into
account a loss of randomness.

A random number generator based on linear congruence is fast and, if
written well, "random enough" for most purposes. You could seed it with
one number from rand(), if this is a superior source of random numbers.

See question 13.15 of the FAQ of this ng. You may also get better
replies in a newsgroup that''s not specific to C, like comp.programming
and sci.crypt.random-numbers (but read their FAQs first, when
appropriate, I have not).

(Pseudo)-random number generation is its own field of study in computer
programming.

S.


Skarmander写道:
Skarmander wrote:
qu ****** @ yahoo.com 写道:
qu******@yahoo.com wrote:
假设我有一个功能rand()可以生成一个0到100之间随机数的整数。假设rand()非常昂贵。什么
是在0和
100之间生成10个不同随机数的最快方法? (只调用rand()10次......)
Suppose I have a function rand() that can generate one integer random
number between 0 and 100. Suppose also rand() is very expensive. What
is the fastest way to generate 10 different random number between 0 and
100? (call rand() only 10 times...)


使用不贵的rand(),可能会导致
帐户失去随机性。


Use a different rand() that is not expensive, possibly taking into
account a loss of randomness.

A random number generator based on linear congruence is fast and, if
written well, "random enough" for most purposes. You could seed it with
one number from rand(), if this is a superior source of random numbers.



更新到我自己的回复:一个流行的快速RNG是传闻要超过

甚至LC,而具有更好的统计特性的是Mersenne

Twister( http://www.math.sci.hiroshima-u.ac.j...t/ MT / emt.html)

附带C源代码。


S.


Update to my own reply: a popular fast RNG that is rumored to outpace
even LC while having much better statistical properties is the Mersenne
Twister (http://www.math.sci.hiroshima-u.ac.j...t/MT/emt.html),
which comes with C source.

S.

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

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