[正文内容]

danielcota/LoopMix128

一个非常快速的 64 位 PRNG,具有 2^128 周期,已验证注入性,通过了 BigCrush 和 PractRand (32TB) 测试。

License

MIT license

25 stars 1 fork Branches Tags Activity

LoopMix128:快速且健壮的 2^128 周期 PRNG

该仓库包含 LoopMix128,一种速度极快的伪随机数生成器 (PRNG),保证周期为 2^128,经过验证的注入性,并且在 BigCrush 和 PractRand (32TB) 中都干净地通过了测试。 它专为速度和统计质量都很重要的非加密应用程序而设计。

特性

性能

算法细节

// Golden ratio fractional part * 2^64
const uint64_t GR = 0x9e3779b97f4a7c15ULL;
// Initialized to non-zero with SplitMix64 (or equivalent)
uint64_t slow_loop, fast_loop, mix; 
// Helper for rotation
static inline uint64_t rotateLeft(const uint64_t x, int k) {
  return (x << k) | (x >> (64 - k));
}
// --- LoopMix128 ---
uint64_t loopMix128() {
 uint64_t output = GR * (mix + fast_loop);
 // slow_loop acts as a looping high counter (updating once per 2^64 calls) to ensure a 2^128 period
 if ( fast_loop == 0 ) {
  slow_loop += GR;
  mix ^= slow_loop;
  }
 // A persistent non-linear mix that does not affect the period of fast_loop and slow_loop
 mix = rotateLeft(mix, 59) + fast_loop;
 // fast_loop loops over a period of 2^64
 fast_loop = rotateLeft(fast_loop, 47) + GR;
 return output;
 }

(注意:上面的代码显示了核心逻辑。有关完整的 seeding 和用法示例,请参见实现文件。)

并行流

由于 LoopMix128 的 192 位状态经过验证的注入性,因此可以按以下方式实现并行流:

PractRand 测试(使用不同的种子)

由于运行 BigCrush 和 PractRand 的行为可能会因初始 seeding 状态而异,因此还使用不同的初始种子(使用 SplitMix64 进行 seeding)多次从 256M 运行到 8GB PractRand。 以下是在 LoopMix128 和一些参考 PRNG 运行 1000 次 PractRand 时可疑结果的总数:

LoopMix128     0 failures, 24 suspicious
xoroshiro256++   0 failures, 27 suspicious
xoroshiro128++   0 failures, 28 suspicious
wyrand       0 failures, 32 suspicious
/dev/urandom    0 failures, 37 suspicious

创建

由 Daniel Cota 在偶然的情况下陷入 PRNG 兔子洞之后创建。

关于

一个非常快速的 64 位 PRNG,具有 2^128 周期,已验证注入性,通过了 BigCrush 和 PractRand (32TB) 测试。

Resources

Readme

License

MIT license Activity

Stars

25 stars

Watchers

2 watching

Forks

1 fork Report repository

Releases

No releases published

Packages 0

No packages published

Languages