RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
uni_rand.cpp
Go to the documentation of this file.
1 //
2 // File = uni_rand.cpp
3 //
4 #include "uni_rand.h"
5 
6 #define MULTIPLIER 16807
7 #define MODULUS 2147483647
8 #define MOD_RECIP (1.0 / MODULUS)
9 
10 #define SCHRAGE_QUOTIENT 127773
11 // equals integer part of (MODULUS/MULTIPLIER)
12 
13 #define SCHRAGE_REMAINDER 2836
14 // equals MODULUS - (SCHRAGE_QUOTIENT * MULTIPLIER)
15 
16 #define MASK 123459876
17 
18 float
19 UniformRandom(long* seed)
20 {
21  long temp;
22  float result;
23 
24  temp = (*seed) / SCHRAGE_QUOTIENT;
25  *seed =
26  MULTIPLIER * (*seed - temp * SCHRAGE_QUOTIENT) - SCHRAGE_REMAINDER * temp;
27  if (*seed < 0)
28  *seed += MODULUS;
29 
30  // get floating point value from seed
31  result = float(MOD_RECIP * (*seed));
32 
33  return (result);
34 }
35 
36 double
38 {
39  long temp;
40  double result;
41  temp = (*seed) / SCHRAGE_QUOTIENT;
42  *seed =
43  MULTIPLIER * (*seed - temp * SCHRAGE_QUOTIENT) - SCHRAGE_REMAINDER * temp;
44  if (*seed < 0)
45  *seed += MODULUS;
46  result = MOD_RECIP * (*seed);
47 
48  return (result);
49 }
#define MODULUS
Definition: uni_rand.cpp:7
#define MOD_RECIP
Definition: uni_rand.cpp:8
double DoubleUniformRandom(long *seed)
Definition: uni_rand.cpp:37
float UniformRandom(long *seed)
Definition: uni_rand.cpp:19
#define SCHRAGE_QUOTIENT
Definition: uni_rand.cpp:10
#define MULTIPLIER
Definition: uni_rand.cpp:6
#define SCHRAGE_REMAINDER
Definition: uni_rand.cpp:13