]> icculus.org git repositories - btb/d2x.git/blob - maths/rand.c
899980a159dc6b1fe22aa0bbe6c05d8a384aa284
[btb/d2x.git] / maths / rand.c
1 // Descent random number stuff...
2 // rand has different ranges on different machines...
3
4 #include <conf.h>
5 #include <stdlib.h>
6
7 #ifdef NO_WATCOM_RAND
8 void d_srand(unsigned int seed)
9 {
10  srand(seed);
11 }
12
13 int d_rand()
14 {
15  return rand()&0x7fff;
16 }
17 #else
18 static unsigned int d_rand_seed;
19
20 int d_rand() {
21         return ((d_rand_seed = d_rand_seed * 0x41c64e6d + 0x3039) >> 16) & 0x7fff;
22 }
23
24 void d_srand(unsigned int seed) {
25         d_rand_seed = seed;
26 }
27 #endif