Showing the changes to src/core/util_math.cpp (1 of 3 files). Show all
Unified · Split
| @@ -75,8 +75,16 @@ double trunc( double a ) · 74 unmodified lines | ||
| 75 | 75 | // desc: chuck wrappers for random number generators |
| 76 | 76 | // 1.5.0.1 (ge) using mt19937 (requires c++11) |
| 77 | 77 | //----------------------------------------------------------------------------- |
| 78 | +// mersenne twister RNG, based on the Mersenne prime (2^19937-1) | |
| 78 | 79 | static std::mt19937 g_ck_global_rng; |
| 80 | +// ck_random() returns a signed int no greater than CK_RANDOM_MAX | |
| 81 | +// to maintain parity between 64-bit and 32-bit systems, CK_RANDOM_MAX is set | |
| 82 | +// to 0x7fffffff (or 2,147,483,647--the largest 32-bit signed number) rather | |
| 83 | +// than mt19937's actual max of 0xffffffff (or 4,294,967,295, 2^32-1); this | |
| 84 | +// is ensured using modulo; the slight skewing of the resulting RNG distribution | |
| 85 | +// is considered acceptable | |
| 79 | 86 | t_CKINT ck_random() { return g_ck_global_rng() % CK_RANDOM_MAX; } |
| 87 | +// seed the random number generator | |
| 80 | 88 | void ck_srandom( unsigned s ) { g_ck_global_rng.seed(s); } |
| 81 | 89 | //----------------------------------------------------------------------------- |
| 82 | 90 | #else // using old school random (pre-c++11) |
| @@ -112,8 +120,7 @@ double ck_remainder( double a, double b ) · 29 unmodified lines | ||
| 112 | 120 | |
| 113 | 121 | |
| 114 | 122 | |
| 115 | −// the following 6 functions are | |
| 116 | −// lifted from PD source | |
| 123 | +// the following 6 functions are lifted from PD source | |
| 117 | 124 | // specifically x_acoustics.c |
| 118 | 125 | // http://puredata.info/downloads |
| 119 | 126 | #define LOGTWO 0.69314718055994528623 |