no more repeating code in xoshiro/xoroshiro

This commit is contained in:
2022-10-24 04:32:06 +06:00
parent f33804f5b8
commit 66935ae437
21 changed files with 214 additions and 204 deletions

View File

@@ -6,7 +6,7 @@ worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
#include "../../krandom.h"
#include "xoshiro128.h"
/* This is xoshiro128++ 1.0, one of our 32-bit all-purpose, rock-solid
generators. It has excellent speed, a state size (128 bits) that is
@@ -23,13 +23,8 @@ static inline uint32 rotl(const uint32 x, int k) {
return (x << k) | (x >> (32 - k));
}
typedef union {
uint64 merged[2];
uint32 s[4];
} _state_t;
uint32 xoshiro128plusplus_next(void* _state){
_state_t* state=_state;
xoshiro128_state* state=_state;
const uint32 result = rotl(state->s[0] + state->s[3], 7) + state->s[0];
const uint32 t = state->s[1] << 9;
@@ -45,11 +40,3 @@ uint32 xoshiro128plusplus_next(void* _state){
return result;
}
void* xoshiro128plusplus_init(uint64 seed){
_state_t* state=malloc(sizeof(_state_t));
splitmix64_state splitmix=splitmix64_init(seed);
state->merged[0]=splitmix64_next(splitmix);
state->merged[1]=splitmix64_next(splitmix);
return state;
}