no more repeating code in xoshiro/xoroshiro
This commit is contained in:
@@ -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.1, one of our 32-bit all-purpose, rock-solid
|
||||
generators. It has excellent speed, a state size (128 bits) that is
|
||||
@@ -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 xoshiro128starstar_next(void* _state){
|
||||
_state_t* state=_state;
|
||||
xoshiro128_state* state=_state;
|
||||
const uint32 result = rotl(state->s[1] * 5, 7) * 9;
|
||||
|
||||
const uint32 t = state->s[1] << 9;
|
||||
@@ -48,11 +43,3 @@ uint32 xoshiro128starstar_next(void* _state){
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void* xoshiro128starstar_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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user