diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-07-18 00:03:47 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-07-18 00:03:47 +0000 |
commit | 25e92bd967ce404ebe9bf8e6ff7b6b9f5f32e8f9 (patch) | |
tree | 58059d6f5d8bf7134d86dddf629f36f512fb992a /firmware/common/random.c | |
parent | 3a62b56740856226e6debf6c2f7a6cdb0435db80 (diff) | |
download | rockbox-25e92bd967ce404ebe9bf8e6ff7b6b9f5f32e8f9.tar.gz rockbox-25e92bd967ce404ebe9bf8e6ff7b6b9f5f32e8f9.zip |
Vastly improved, now working, random! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1379 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/random.c')
-rw-r--r-- | firmware/common/random.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/firmware/common/random.c b/firmware/common/random.c index 1e65eefaa0..5471534e34 100644 --- a/firmware/common/random.c +++ b/firmware/common/random.c | |||
@@ -142,12 +142,16 @@ int rand(void) | |||
142 | { | 142 | { |
143 | int y; | 143 | int y; |
144 | 144 | ||
145 | if(--left < 0) | 145 | if(--left < 0) { |
146 | return rand_reload(); | 146 | y = rand_reload(); |
147 | 147 | } | |
148 | y = *next++; | 148 | else { |
149 | y ^= (y >> 11); | 149 | y = *next++; |
150 | y ^= (y << 7) & 0x9D2C5680U; | 150 | y ^= (y >> 11); |
151 | y ^= (y << 15) & 0xEFC60000U; | 151 | y ^= (y << 7) & 0x9D2C5680U; |
152 | return (y ^ (y >> 18)) & ((2^31)-1); /* 31-bit limit by Björn Stenberg*/ | 152 | y ^= (y << 15) & 0xEFC60000U; |
153 | y ^= (y >> 18); | ||
154 | } | ||
155 | |||
156 | return y & 0x7fffffff; /* 31-bit limit by Björn Stenberg*/ | ||
153 | } | 157 | } |