summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/random.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/firmware/common/random.c b/firmware/common/random.c
index 899ce4af4b..ebe60b091f 100644
--- a/firmware/common/random.c
+++ b/firmware/common/random.c
@@ -56,11 +56,11 @@
56#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move highest bit of u to 56#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move highest bit of u to
57 highest bit of v */ 57 highest bit of v */
58 58
59static unsigned int state[N+1]; /* state vector + 1 to not violate ANSI C */ 59static unsigned long state[N+1]; /* state vector + 1 to not violate ANSI C */
60static unsigned int *next; /* next random value is computed from here */ 60static unsigned long *next; /* next random value is computed from here */
61static int left = -1; /* can *next++ this many times before reloading */ 61static int left = -1; /* can *next++ this many times before reloading */
62 62
63void srand(unsigned int seed) 63void srand(unsigned long seed)
64{ 64{
65 /* 65 /*
66 * We initialize state[0..(N-1)] via the generator 66 * We initialize state[0..(N-1)] via the generator
@@ -108,16 +108,16 @@ void srand(unsigned int seed)
108 * so-- that's why the only change I made is to restrict to odd seeds. 108 * so-- that's why the only change I made is to restrict to odd seeds.
109 */ 109 */
110 110
111 unsigned int x = (seed | 1U) & 0xFFFFFFFFU, *s = state; 111 unsigned long x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
112 int j; 112 int j;
113 113
114 for(left=0, *s++=x, j=N; --j; 114 for(left=0, *s++=x, j=N; --j;
115 *s++ = (x*=69069U) & 0xFFFFFFFFU); 115 *s++ = (x*=69069U) & 0xFFFFFFFFU);
116} 116}
117 117
118static int rand_reload(void) 118static long rand_reload(void)
119{ 119{
120 unsigned int *p0=state, *p2=state+2, *pM=state+M, s0, s1; 120 unsigned long *p0=state, *p2=state+2, *pM=state+M, s0, s1;
121 int j; 121 int j;
122 122
123 if(left < -1) 123 if(left < -1)
@@ -135,12 +135,12 @@ static int rand_reload(void)
135 s1 ^= (s1 >> 11); 135 s1 ^= (s1 >> 11);
136 s1 ^= (s1 << 7) & 0x9D2C5680U; 136 s1 ^= (s1 << 7) & 0x9D2C5680U;
137 s1 ^= (s1 << 15) & 0xEFC60000U; 137 s1 ^= (s1 << 15) & 0xEFC60000U;
138 return (int)s1 ^ (s1 >> 18); 138 return (long)s1 ^ (s1 >> 18);
139} 139}
140 140
141int rand(void) 141long rand(void)
142{ 142{
143 unsigned int y; 143 unsigned long y;
144 144
145 if(--left < 0) { 145 if(--left < 0) {
146 y = rand_reload(); 146 y = rand_reload();