This commit is contained in:
2023-06-08 15:15:50 +06:00
parent c5585bbb0c
commit 080bbb28fd
22 changed files with 124 additions and 239 deletions

View File

@@ -26,7 +26,7 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
The state must be seeded so that it is not everywhere zero. If you have
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
output to fill s.
output to fill s.
NOTE: the parameters (a=24, b=16, b=37) of this version give slightly
better results in our test than the 2016 version (a=55, b=14, c=36).
@@ -36,8 +36,7 @@ static inline u64 rotl(const u64 x, i32 k) {
return (x << k) | (x >> (64 - k));
}
u64 xoroshiro128plus_next(void* _state){
xoroshiro128_state* state=_state;
u64 xoroshiro128plus_next(xoroshiro128_state* state){
const u64 s0 = state->s[0];
u64 s1 = state->s[1];
const u64 result = s0 + s1;
@@ -49,11 +48,9 @@ u64 xoroshiro128plus_next(void* _state){
return result;
}
void* xoroshiro128_init(u64 seed){
xoroshiro128_state* state=malloc(sizeof(xoroshiro128_state));
splitmix64_state* splitmix=splitmix64_init(seed);
state->s[0]=splitmix64_next(splitmix);
state->s[1]=splitmix64_next(splitmix);
splitmix64_free(splitmix);
return state;
void xoroshiro128_construct(xoroshiro128_state* state, u64 seed){
splitmix64_state sm_state;
splitmix64_construct(&sm_state, seed);
state->s[0]=splitmix64_next(&sm_state);
state->s[1]=splitmix64_next(&sm_state);
}