| 1 |
/* |
| 2 |
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 |
* It is copyright by its individual contributors, as recorded in the |
| 4 |
* project's Git history. See COPYING.txt at the top level for license |
| 5 |
* terms and a link to the Git history. |
| 6 |
*/ |
| 7 |
/* |
| 8 |
* |
| 9 |
* Descent random number stuff... |
| 10 |
* rand has different ranges on different machines... |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
#include <stdlib.h> |
| 15 |
#include "maths.h" |
| 16 |
|
| 17 |
namespace dcx { |
| 18 |
|
| 19 |
#ifdef NO_WATCOM_RAND |
| 20 |
|
| 21 |
void d_srand(unsigned int seed) |
| 22 |
{ |
| 23 |
srand(seed); |
| 24 |
} |
| 25 |
|
| 26 |
int d_rand() |
| 27 |
{ |
| 28 |
return rand() & 0x7fff; |
| 29 |
} |
| 30 |
|
| 31 |
#else |
| 32 |
|
| 33 |
static unsigned int d_rand_seed; |
| 34 |
|
| 35 |
int d_rand() |
| 36 |
{ |
| 37 |
return ((d_rand_seed = d_rand_seed * 0x41c64e6d + 0x3039) >> 16) & 0x7fff; |
| 38 |
} |
| 39 |
|
| 40 |
void d_srand(unsigned int seed) |
| 41 |
{ |
| 42 |
d_rand_seed = seed; |
| 43 |
} |
| 44 |
|
| 45 |
#endif |
| 46 |
|
| 47 |
} |