是否有一个伪随机数生成足够简单,做在你的头上?你的、随机数、头上、有一个

2023-09-11 03:17:11 作者:_劳资有罪丶

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

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.