Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- unsigned int cur = 0, twister[624] = {0};
- void generate_seed(){
- int i;
- for (i = 0; i < 624; i++){
- unsigned int x = (twister[i] & 0x80000000) + (twister[(i + 1) % 624] & 0x7fffffff);
- twister[i] = twister[(i + 397) % 624] ^ (x >> 1);
- if (!(x & 1)) twister[i] = (twister[i] ^ 0x9908b0df);
- }
- }
- int random(){
- if (cur == 0) generate_seed();
- unsigned int res = twister[cur];
- cur++;
- if (cur == 624) cur = 0;
- res = res ^ (res >> 11U);
- res = res ^ ((res << 7U) & 0x9d2c5680);
- res = res ^ ((res << 15U) & 0xefc60000);
- res = res ^ (res >> 18U);
- return res;
- }
- int main(){
- int i, j;
- srand(time(0));
- twister[0] = rand();
- for (i = 1; i < 624; i++){
- twister[i] = (1812433253U * twister[i - 1]) ^ (twister[i - 1] >> 30U);
- }
- int lim = 1000000;
- int even = 0, odd = 0;
- for (i = 0; i < lim; i++){
- int r = random();
- if (r & 1) odd++;
- else even++;
- }
- printf("%d %d\n", even, odd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement