[Issue 10900] Mersenne Twister should have a 64-bit (ulong) version

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 16 08:30:04 PST 2017


https://issues.dlang.org/show_bug.cgi?id=10900

--- Comment #1 from github-bugzilla at puremagic.com ---
Commit pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/45c515f267b687032b6672921d28b5c7938f6154
Add 64-bit implementation of MersenneTwisterEngine

With the required tempering parameter `d` introduced by the previous
patch, we can now introduce the standard 64-bit implementation of the
Mersenne Twister.  See https://en.wikipedia.org/wiki/Mersenne_Twister
for an explanation of the chosen constants.

Some minimal unittests have been added similar to those already present
for the 32-bit `Mt19937`.  These can be verified by comparison to C++11
by compiling and running the following C++ program:

/****************************************************************/

int main ()
{
    static_assert(std::mt19937_64::default_seed == 5489,
                  "Default seed does not match Phobos!");
    std::mt19937_64 gen(std::mt19937_64::default_seed);
    std::cout << gen() << std::endl;
    for (int i = 0; i < 9998; ++i) {
        gen();
    }
    std::cout << gen() << std::endl;
}
/****************************************************************/

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.

Fixes Issue #10900 <https://issues.dlang.org/show_bug.cgi?id=10900>.

--


More information about the Digitalmars-d-bugs mailing list