Created
September 11, 2014 09:05
-
-
Save kazoo04/4d323395c51d7ae9657f to your computer and use it in GitHub Desktop.
XorShift_example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <limits.h> | |
unsigned long xorshift() { | |
static unsigned long x=123456789, y=362436069, z=521288629, w=88675123; | |
unsigned long t; | |
t = (x ^ (x << 11)); | |
x = y; | |
y = z; | |
z = w; | |
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); | |
return w; | |
} | |
int main(void) { | |
// 最初の方の値は捨てるといいかもしれない | |
for(int i = 0; i < 1000000; i++) xorshift(); | |
for(int i = 0; i < 30; i++) { | |
double r = 0.48 + 0.02 * ((double)xorshift() / ((double)ULONG_MAX)); | |
printf("%.4lf\n", r); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment