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, our best and fastest 32-bit generator for 32-bit
floating-point numbers. We suggest to use its upper bits for
@@ -26,13 +26,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 xoshiro128plus_next(void* _state){
_state_t* state=_state;
xoshiro128_state* state=_state;
const uint32 result = state->s[0] + state->s[3];
const uint32 t = state->s[1] << 9;
@@ -49,9 +44,9 @@ uint32 xoshiro128plus_next(void* _state){
return result;
}
void* xoshiro128plus_init(uint64 seed){
_state_t* state=malloc(sizeof(_state_t));
splitmix64_state splitmix=splitmix64_init(seed);
void* xoshiro128_init(uint64 seed){
xoshiro128_state* state=malloc(sizeof(xoshiro128_state));
splitmix64_state* splitmix=splitmix64_init(seed);
state->merged[0]=splitmix64_next(splitmix);
state->merged[1]=splitmix64_next(splitmix);
return state;