diff --git a/C/scratchpad/xorshift b/C/scratchpad/xorshift index 552d370b..2a32b0b1 100755 Binary files a/C/scratchpad/xorshift and b/C/scratchpad/xorshift differ diff --git a/C/scratchpad/xorshift.c b/C/scratchpad/xorshift.c index e3b8ee81..33a9d8d2 100644 --- a/C/scratchpad/xorshift.c +++ b/C/scratchpad/xorshift.c @@ -12,15 +12,21 @@ uint32_t xorshift32(uint32_t* state) return *state = x; } +float rand_xorshift32(uint32_t* state){ + return (float) xorshift32(state) / UINT32_MAX; +} + int main(){ uint32_t** states = malloc(4 * sizeof(uint32_t*)); for(int i=0; i<4;i++){ states[i] = malloc(sizeof(uint32_t)); *states[i] = i + 1; } - - printf("%i\n", xorshift32(states[0])); - printf("%i\n", xorshift32(states[1])); + + for(int i=0; i<100; i++){ + printf("%u\n", xorshift32(states[0])); + printf("%f\n", rand_xorshift32(states[1])); + } for(int i=0; i<4;i++){ free(states[i]); } @@ -28,3 +34,6 @@ int main(){ return 0; } + +// See +// https://en.wikipedia.org/wiki/Xorshift