伪随机外观的一对一的int32-> INT32功能外观、功能、GT

2023-09-11 03:32:13 作者:(厮守伱一辈子)

我要寻找一个int32-> INT32功能是

I am looking for a int32->int32 function that is

双射(一次对一的对应关系) 廉价至少以计算在一个方向 变换递增序列0,1,2,3,...到一个序列看上去像一个良好的伪随机序列(〜一半比特翻转时由少数的参数的变化,没有明显的图案)

推荐答案

乘以一个大奇数和异或具有不同的功能。

Multiply by a large odd number and xor with a different one.

双射:奇数有两个乘法逆模的力量,因此乘法被乘以逆撤消。和XOR,当然,另一个异或撤消。

Bijection: odd numbers have a multiplicative inverse modulo powers of two, so the multiplication is undone by a multiplication by the inverse. And xor is, of course, undone by another xor.

这基本上是如何线性同余伪随机数生成器的工作原理。

This is basically how the linear congruence pseudo random number generator works.