Changeset 1547
- Timestamp:
- Jan 3, 2007, 10:20:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/random.c
r1523 r1547 28 28 #include "random.h" 29 29 30 static unsigned long ctx = 1; 31 30 32 void _zz_srand(uint32_t seed) 31 33 { 32 srand(seed ^ 0x12345678);34 ctx = (seed ^ 0x12345678); 33 35 } 34 36 35 37 uint32_t _zz_rand(uint32_t max) 36 38 { 37 if(max <= RAND_MAX)38 return rand() % max;39 /* Could be better, but do we care? */ 40 long hi, lo, x; 39 41 40 /* Could be better, but do we care? */ 41 return (uint32_t)((max * 1.0) * (rand() / (RAND_MAX + 1.0))); 42 hi = ctx / 12773L; 43 lo = ctx % 12773L; 44 x = 16807L * lo - 2836L * hi; 45 if(x <= 0) 46 x += 0x7fffffffL; 47 return (ctx = x) % (unsigned long)max; 42 48 } 43 49
Note: See TracChangeset
for help on using the changeset viewer.