FreeCalypso > hg > fc-selenite
comparison src/libsys/rand.c @ 86:425ab6d987f3
src/libsys: pieced together from Citrine
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 20 Jul 2018 20:36:19 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
85:4ef6808ea50e | 86:425ab6d987f3 |
---|---|
1 /* | |
2 * This version of rand() has been lifted from Ancient UNIX, and modified | |
3 * to match the version used in TI's TCS211 GSM firmware, as revealed by | |
4 * disassembly of rand.obj in the rts16le_flash.lib binary library used | |
5 * by that semi-src package. TI's version (most likely from their compiler | |
6 * tools group, rather than the GSM fw group, but who knows) uses the | |
7 * same trivial implementation of rand() as the original Ancient UNIX libc, | |
8 * but with one change: TI's return value is right-shifted by 16 bits | |
9 * compared to what the Ancient UNIX rand() would have returned. | |
10 * The caller thus gets back only 15 pseudo-random bits rather than 31, | |
11 * but then the lower bits of the original rand() return value are | |
12 * known to be pretty bad. | |
13 * | |
14 * rand() is used by some FFS code in reclaim.c. If we don't provide our | |
15 * own version of rand() and let the linker pull the version from newlib, | |
16 * the link fails because the latter uses malloc. This ancient implementation | |
17 * of rand() is quite poor, but my plan is to look into possibly adopting | |
18 * some better PRNG after we get the basic TI GSM firmware reintegrated. | |
19 */ | |
20 | |
21 static long randx = 1; | |
22 | |
23 srand(x) | |
24 unsigned x; | |
25 { | |
26 randx = x; | |
27 } | |
28 | |
29 rand() | |
30 { | |
31 return ((randx = randx * 1103515245 + 12345) & 0x7fffffff) >> 16; | |
32 } |