00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef INCLUDE_BASE_MZRAN13
00015 #define INCLUDE_BASE_MZRAN13
00016
00017 #include <base/inttypes.h>
00018
00019 namespace base
00020 {
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class MZRan13
00031 {
00032 public:
00033
00034
00035
00036 MZRan13(uint32_t seed);
00037
00038
00039
00040
00041 uint32_t operator()();
00042 private:
00043 uint32_t x, y, z, n, c;
00044 };
00045
00046 inline MZRan13::MZRan13(uint32_t s)
00047 : x(s ^ 521288629), y(s ^ 362436069)
00048 , z(s ^ 16163801), n(s ^ 1131199209)
00049 {
00050 c = (y > z ? 1 : 0);
00051 }
00052
00053 inline uint32_t MZRan13::operator()()
00054 {
00055 uint32_t s;
00056 if (y > x + c) {
00057 s = y - (x + c);
00058 c = 0;
00059 } else {
00060 s = (y - (x + c) - 18) & 0xffffffff;
00061 c = 1;
00062 }
00063 x = y;
00064 y = z;
00065
00066 return ((z = s) + (n = 69069 * n + 1013904243)) & 0xffffffff;
00067 }
00068 }
00069
00070 #endif