伪随机外观的一对一的int32-> INT32功能 [英] Pseudo-random-looking one-to-one int32->int32 function
本文介绍了伪随机外观的一对一的int32-> INT32功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要寻找一个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.
这篇关于伪随机外观的一对一的int32-> INT32功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文