简单的PRNG? [英] simple PRNG?
问题描述
有人能指点我一个简单,快速的RRNG函数来生成指定范围内的随机整数
吗?重要的是,
范围内的每个值具有相同的概率(均匀分布)。
我不想使用不可靠的rand()函数,但我做我不想使用像MT一样复杂的代码来膨胀我的代码。我只是在寻找
a短代码片段,我可以复制而不用担心许可。
该函数应该在有限的平台上工作(没有浮点数学
拜托,即使在int只有16位的平台上工作也会很好。
完美)。
我搜索了这个群组和网络,但我可以找不到符合要求的任何东西
Can anyone point me to a simple, fast RRNG function to generate random ints
within a specified range? It is important that each value within the range
has the same probability (uniform distribution).
I do not want to use the unreliable rand() function, but I do not want to
bloat my code with something as complex as MT either. I am just looking for
a short code snippet that I can copy without worrying about licensing.
The function should work on limited platforms (no floating-point math
please, one that works even on platforms where int is only 16 bit would be
perfect).
I did search this group and the web but I could not find anything which
meets the requirements.
推荐答案
copx写道:
copx wrote:
>
任何人都可以指向一个简单,快速的RRNG函数来生成随机整数
在指定的范围内范围?重要的是,
范围内的每个值具有相同的概率(均匀分布)。
我不想使用不可靠的rand()函数,但我做我不想使用像MT一样复杂的代码来膨胀我的代码。我只是在寻找
a短代码片段,我可以复制而不用担心许可。
该函数应该在有限的平台上工作(没有浮点数学
拜托,即使在int只有16位的平台上工作也会很好。
完美)。
我搜索了这个群组和网络,但我可以找不到任何符合要求的
。
>
Can anyone point me to a simple, fast RRNG function to generate random ints
within a specified range? It is important that each value within the range
has the same probability (uniform distribution).
I do not want to use the unreliable rand() function, but I do not want to
bloat my code with something as complex as MT either. I am just looking for
a short code snippet that I can copy without worrying about licensing.
The function should work on limited platforms (no floating-point math
please, one that works even on platforms where int is only 16 bit would be
perfect).
I did search this group and the web but I could not find anything which
meets the requirements.
您需要多么简单,多快和多短?
-
Morris Dovey
DeSoto Solar
美国爱荷华州DeSoto
http://www.iedu.com/DeSoto/
" Morris多维" < mr ***** @ iedu.comschrieb im Newsbeitrag
news:47 ************** @ iedu.com ...
"Morris Dovey" <mr*****@iedu.comschrieb im Newsbeitrag
news:47**************@iedu.com...
copx写道:
copx wrote:
>>
任何人都可以指向一个简单,快速的RRNG功能在指定范围内生成随机
的内容?重要的是
范围内的每个值具有相同的概率(均匀分布)。
我不想使用不可靠的rand()函数,但我不想<使用像MT这样复杂的东西来膨胀我的代码。我正在寻找
一个简短的代码片段,我可以复制而不用担心许可。
该功能应该在有限的平台上工作(没有浮点数学请
即使在int只有16位的平台上也能完美地工作。
我确实搜索了这个组和网络,但我找不到符合要求的任何东西。
>>
Can anyone point me to a simple, fast RRNG function to generate random
ints
within a specified range? It is important that each value within the
range
has the same probability (uniform distribution).
I do not want to use the unreliable rand() function, but I do not want to
bloat my code with something as complex as MT either. I am just looking
for
a short code snippet that I can copy without worrying about licensing.
The function should work on limited platforms (no floating-point math
please, one that works even on platforms where int is only 16 bit would
be
perfect).
I did search this group and the web but I could not find anything which
meets the requirements.
您需要多么简单,多快和多短?
How simple, how fast, and how short do you require?
不超过一页代码会很好(简单我意味着很少
代码,不一定容易理解码)。快速意味着算法
应该能够在80386
级别的机器上每秒生成数百个随机数。当然,8086每秒10,000个数字甚至更好!
! ;)
Not more than a page of code would be nice (with "simple" I meant little
code, not necessary easy to understand code). Fast means that the algorithm
should be able to generate hundreds of random numbers per second on a 80386
level machine at least. Of course, 10,000 numbers per second on a 8086 are
even better! ;)
copx说:
copx said:
>
理查德希思菲尔德 < rj*@see.sig.invalidschrieb im Newsbeitrag
新闻:MO *************************** *** @ bt.com ...
>
"Richard Heathfield" <rj*@see.sig.invalidschrieb im Newsbeitrag
news:MO******************************@bt.com...
< snip>
<snip>
>但严重的是,这是你要么自己做的事情,要么付钱给某人为你做。
>But seriously, this is the kind of thing you either do yourself, or pay
someone to do for you.
向某人支付大约20行代码?
Paying someone for about 20 lines of code?
你怎么知道它只有20行代码?是什么让你觉得
短==简单?仅仅因为一个算法并没有花费太多的代码来表示,这并不意味着要想出来并正确地实现它是很简单的。 E = mc ^ 2很容易表达,但确定它是正确的需要相当多的数学。
< snip>
How do you know it''s only 20 lines of code? And what makes you think that
short==simple? Just because an algorithm doesn''t take much code to
express, that doesn''t mean it is trivial to think it up and implement it
correctly. E=mc^2 is simple enough to express, but it took quite a lot of
mathematics to establish that it was correct.
<snip>
我没想到有人会为我写一些这样的东西,只要有人知道在哪里可以找到它。
I did not expect that someone would write such a thing from
scratch for me, just that someone might knew where to find it.
足够公平 - 但你可以通过询问算法来获得更好的结果
group。
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
Fair enough - but you might get better results by asking in an algorithms
group.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
这篇关于简单的PRNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!