是否有一个伪随机数生成足够简单,做在你的头上? [英] Is there a pseudo-random number generator simple enough to do in your head?

查看:203
本文介绍了是否有一个伪随机数生成足够简单,做在你的头上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何伪随机数生成器是很容易做心算,或者心算加指望你的手指。显然,这限制相当简单的数学 - 它需要某个人的程序员,而不是一个数学天才

Are there are any pseudo-random number generators that are easy enough to do with mental arithmetic, or mental arithmetic plus counting on your fingers. Obviously this limits to fairly simple math - it needs to be something someone of average mathematical ability can do, or maybe average ability for a programmer, not a math prodigy.

我发现最简单的是中东最小二乘法,但它不仅是已知的穷源随机性,它仍然看起来太复杂,离不开笔和纸。

The simplest I have found is the Middle square method, but not only is it known to be a poor source of randomness, it still looks too complex to do without pencil and paper.

如果做到这一点的唯一方法是通过限制的范围内,如可能只可以输出8位数字,这很好。我怀疑的标准PRNG算法之一将是一个8位的版本很简单,但我不知道够不够简化其中的任何从32位版本的8位版本。 (所有那些我看着依赖于专门挑种子数是不同,这取决于有多少位正在使用,并且通常只有32位和64位的例子给出。)

If the only way to do this is by limiting the range, like maybe it only can output 8 bit numbers, that is fine. I suspect one of the standard PRNG algorithms would be simple enough in an 8 bit version, but I don't know enough to simplify any of them from the 32 bit version to an 8 bit version. (All the ones I looked at depend on specially picked seed numbers that are different depending how many bits you are working with, and usually only 32 and 64 bit examples are given.)

推荐答案

一个线性反馈移位寄存器是pretty的简单,只要你熟悉的二进制思想(或者十六进制,因为它很容易的映射二)。

A linear feedback shift register is pretty simple, as long as you're comfortable with thinking in binary (or maybe hex, since it's easy to map between the two).

一个更复杂的是 Xorshift 的,但如果你知道你的位操作,​​应该是很有可能一起工作为好。

A more complex one is Xorshift, but if you know your bitwise operations, it should be quite possible to work with as well.

这篇关于是否有一个伪随机数生成足够简单,做在你的头上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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