Commit 59f1a3d
committed
Add unittest for Mersenne Twisters with non-standard word size
The word size for `MersenneTwisterEngine` is determined by the template
parameter `w`, not `UIntType`. For example, a generator with identical
parameters to the standard `Mt19937` but with a `ulong` wordtype should
not produce different results to the standard `uint`-based generator.
This patch adds unittests for the first and 10_000'th values of the
sequences generated by a variety of Mersenne Twister implementations
with non-standard template parameter values.
The values in this unittest can be validated by comparison to C++11 by
compiling and running the following C++ program:
/****************************************************************/
template<class UIntType, size_t w>
void mt_result ()
{
std::mersenne_twister_engine<
UIntType, w, 624, 397, 31,
0x9908b0df, 11, 0xffffffff, 7,
0x9d2c5680, 15,
0xefc60000, 18, 1812433253> gen;
gen.seed(std::mt19937::default_seed);
std::cout << gen() << std::endl;
for (int i = 0; i < 9998; ++i)
gen();
std::cout << gen() << std::endl;
std::cout << std::endl;
}
int main ()
{
mt_result<uint32_t, 32>();
mt_result<uint64_t, 32>();
mt_result<uint64_t, 48>();
mt_result<uint64_t, 64>();
}
/****************************************************************/
Note that the `for` loop in this example advances the generator 9998
times compared to the D unittest's `popFrontN(9999)` because the first
`gen()` call already advances the generator once.1 parent 45c515f commit 59f1a3d
1 file changed
+13
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
956 | 956 | | |
957 | 957 | | |
958 | 958 | | |
959 | | - | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
960 | 967 | | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
961 | 973 | | |
962 | 974 | | |
963 | 975 | | |
| |||
0 commit comments