-
Notifications
You must be signed in to change notification settings - Fork 3
/
jm_prng.spin
100 lines (73 loc) · 2.9 KB
/
jm_prng.spin
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
92
93
94
95
96
97
98
99
100
'' =================================================================================================
''
'' File....... jm_prng.spin
'' Purpose.... Better psuedo random number generator
'' Author..... Michael Rychlik
'' -- reformatted by Jon "JonnyMac" McPhalen
'' -- see below for terms of use
'' E-mail.....
'' Started.... 31 NOV 2011
'' Updated.... 05 MAY 2012
''
'' =================================================================================================
'' /* Implementation of a 32-bit KISS generator which uses no multiply instructions */
''
'' static unsigned int x=123456789,y=234567891,z=345678912,w=456789123,c=0;
'' unsigned int JKISS32()
'' {
'' int t;
'' y ^= (y<<5); y ^= (y>>7); y ^= (y<<22);
'' t = z+w+c; z = w; c = t < 0; w = t&2147483647;
'' x += 1411392427;
'' return x + y + w;
'' }
var
long x
long y
long z
long w
long c
pub start
x := 123456789
y := 234567891
z := 345678912
w := 456789123
c := 0
pub seed(xx, yy, zz, ww, cc)
if (xx <> 0)
x := xx
if (yy <> 0)
y := yy
if (zz <> 0)
z := zz
if (ww <> 0)
w := 0
c := cc & 1
pub random | t
y ^= (y << 5)
y ^= (y >> 7)
y ^= (y << 22)
t := z + w + c
z := w
c := (t < 0) & 1
w := t & 2147483647
x += 1411392427
return (x + y + w)
dat
{{
Terms of Use: MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}}