gpt4 book ai didi

java - xorshift128+ PRNG 在 java 中的实现,不带 unsigned long

转载 作者:行者123 更新时间:2023-12-01 11:56:05 26 4
gpt4 key购买 nike

使用此 C 代码作为引用(源自 http://en.wikipedia.org/wiki/Xorshift):

uint64_t s[2];
uint64_t xorshift128plus(void) {
uint64_t x = s[0];
uint64_t const y = s[1];
s[0] = y;
x ^= x << 23; // a
x ^= x >> 17; // b
x ^= y ^ (y >> 26); // c
s[1] = x;
return x + y;
}

以下是维护随机性属性方面的等效 java 代码(除了种子和返回值之间的不同映射):

long s[2];
long xorshift128plus(){
long x = s[0];
long y = s[1];
s[0] = y;
x ^= x << 23; // a
x ^= x >>> 17; // b
x ^= y ^ (y >>> 26); // c
s[1] = x;
return x + y;
}

最佳答案

我在 DSI 实用程序中分发了来自 xorshift 系列的 PRNG 的完整实现:​​http://dsiutils.di.unimi.it/docs/it/unimi/dsi/util/package-summary.html

关于java - xorshift128+ PRNG 在 java 中的实现,不带 unsigned long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28441111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com