summaryrefslogtreecommitdiff
path: root/xorshift.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorshift.c')
-rw-r--r--xorshift.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/xorshift.c b/xorshift.c
index ac4d087..528f3db 100644
--- a/xorshift.c
+++ b/xorshift.c
@@ -7,6 +7,7 @@
#include <assert.h>
#include <limits.h>
#include <sys/random.h>
+#include <math.h>
#include <string.h>
#include "structs.h"
@@ -16,23 +17,23 @@ __attribute__((visibility("default"))) bool initialize_states(){
assert( (sizeof(uint32_t) * CHAR_BIT) == 32 );
memset( (void*)&global_rng_state, 0, sizeof(struct rng_state) );
ssize_t state_bytes_read = 0;
- if ( (state_bytes_read = getrandom((void*)&global_rng_state.states, 16 * sizeof(uint32_t), GRND_NONBLOCK)) == -1 )
+ if ( (state_bytes_read = getrandom((void*)&global_rng_state.states, STATE_SIZE * sizeof(uint32_t), GRND_NONBLOCK)) == -1 )
return false;
- if ( (size_t)state_bytes_read < (16 * sizeof(uint32_t)) ){
+ if ( (size_t)state_bytes_read < (STATE_SIZE * sizeof(uint32_t)) ){
errno = EIO;
return false;
}
- global_rng_state.state_idx = global_rng_state.states[7] >> 28;
+ global_rng_state.state_idx = global_rng_state.states[(uint32_t)(floor(STATE_SIZE / 2))] >> SHIFT_VALUE;
errno = 0;
return true;
}
__attribute__((visibility("default"))) uint32_t get_random_output(){
size_t use_state = global_rng_state.state_idx;
- global_rng_state.state_idx = global_rng_state.states[use_state] >> 28;
+ global_rng_state.state_idx = global_rng_state.states[use_state] >> SHIFT_VALUE;
if ( global_rng_state.gen_period_ctr >= 0xffffffff ){
global_rng_state.period_end_ctr++;
- if ( global_rng_state.period_end_ctr >= 16 ){
+ if ( global_rng_state.period_end_ctr >= STATE_SIZE ){
assert( initialize_states() == true );
global_rng_state.period_end_ctr = 0;
}