-
Notifications
You must be signed in to change notification settings - Fork 3
/
xorshift.c
91 lines (77 loc) · 1.74 KB
/
xorshift.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
uint32_t xor32()
{
static uint32_t y = 2463534242UL;
y^=(y<<13); y^=(y>>17); return (y^=(y<<15));
}
uint32_t xor64()
{
static uint32_t x = 123456789, y = 362436069;
uint32_t t = (x^(x<<10)); x = y; return y = (y^(y>>10))^(t^(t>>13));
}
uint32_t xor96()
{
static uint32_t x = 123456789, y = 362436069, z = 521288629;
uint32_t t = (x^(x<<10)); x = y; y = z; return z = (z^(z>>26))^(t^(t>>5));
}
uint32_t xor128()
{
static uint32_t x = 123456789, y = 362436069, z = 521288629,
w = 88675123;
uint32_t t = (x^(x<<11)); x = y; y = z; z = w; return w = (w^(w>>19))^(t^(t>>8));
}
uint32_t xor160()
{
static uint32_t x = 123456789, y = 362436069, z = 521288629,
w = 88675123, v = 5783321;
uint32_t t = (x^(x<<2)); x = y; y = z; z = w; w = v; return v = (v^(v>>4))^(t^(t>>1));
}
uint32_t xorwow()
{
static uint32_t x = 123456789, y = 362436069, z = 521288629,
w = 88675123, v = 5783321, d = 6615241;
uint32_t t = (x^(x>>2)); x = y; y = z; z = w; w = v; v = (v^(v<<4))^(t^(t<<1)); return (d+=362437)+v;
}
int main(void)
{
size_t i;
printf("Xorshift32:");
for(i=0; i<10; ++i)
{
printf(" %"PRIu32, xor32());
}
printf("\n\n");
printf("Xorshift64:");
for(i=0; i<10; ++i)
{
printf(" %"PRIu32, xor64());
}
printf("\n\n");
printf("Xorshift96:");
for(i=0; i<10; ++i)
{
printf(" %"PRIu32, xor96());
}
printf("\n\n");
printf("Xorshift128:");
for(i=0; i<10; ++i)
{
printf(" %"PRIu32, xor128());
}
printf("\n\n");
printf("Xorshift160:");
for(i=0; i<10; ++i)
{
printf(" %"PRIu32, xor160());
}
printf("\n\n");
printf("Xorshift192:");
for(i=0; i<10; ++i)
{
printf(" %"PRIu32, xorwow());
}
printf("\n");
return 0;
}