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 "xoroshiro128.h"
|
||||
|
||||
/* This is xoroshiro128+ 1.0, our best and fastest small-state generator
|
||||
for floating-point numbers, but its state space is large enough only
|
||||
@@ -36,12 +36,8 @@ static inline uint64 rotl(const uint64 x, int k) {
|
||||
return (x << k) | (x >> (64 - k));
|
||||
}
|
||||
|
||||
typedef union {
|
||||
uint32 s[2];
|
||||
} _state_t;
|
||||
|
||||
uint64 xoroshiro128plus_next(void* _state){
|
||||
_state_t* state=_state;
|
||||
xoroshiro128_state* state=_state;
|
||||
const uint64 s0 = state->s[0];
|
||||
uint64 s1 = state->s[1];
|
||||
const uint64 result = s0 + s1;
|
||||
@@ -53,9 +49,9 @@ uint64 xoroshiro128plus_next(void* _state){
|
||||
return result;
|
||||
}
|
||||
|
||||
void* xoroshiro128plus_init(uint64 seed){
|
||||
_state_t* state=malloc(sizeof(_state_t));
|
||||
splitmix64_state splitmix=splitmix64_init(seed);
|
||||
void* xoroshiro128_init(uint64 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);
|
||||
return state;
|
||||
|
||||
Reference in New Issue
Block a user