00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef SIM_RAND_H
00014 #define SIM_RAND_H
00015
00016 #define RAND_MAX_NUM 0x7fffffff
00017
00018 namespace SimRand {
00019 static int __attribute__((unused))
00020 do_rand(unsigned long *ctx)
00021 {
00022
00023
00024
00025
00026
00027
00028
00029
00030 long hi, lo, x;
00031
00032
00033 if (*ctx == 0)
00034 *ctx = 123459876;
00035 hi = *ctx / 127773;
00036 lo = *ctx % 127773;
00037 x = 16807 * lo - 2836 * hi;
00038 if (x < 0)
00039 x += 0x7fffffff;
00040 return ((*ctx = x) % ((unsigned long)RAND_MAX_NUM + 1));
00041 }
00042
00043 extern unsigned long next;
00044
00045 static unsigned int __attribute__((unused)) rand() { return do_rand(&SimRand::next); }
00046 };
00047
00048 #endif