Bug 10900 – Mersenne Twister should have a 64-bit (ulong) version

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-26T04:43:00Z
Last change time
2017-03-22T12:22:09Z
Assigned to
nobody
Creator
joseph.wakeling

Comments

Comment #0 by joseph.wakeling — 2013-08-26T04:43:25Z
Boost.Random's Mersenne Twister implementation defines a 64-bit as well as 32-bit version: #if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T) typedef mersenne_twister_engine<uint64_t,64,312,156,31, UINT64_C(0xb5026f5aa96619e9),29,UINT64_C(0x5555555555555555),17, UINT64_C(0x71d67fffeda60000),37,UINT64_C(0xfff7eee000000000),43, UINT64_C(6364136223846793005)> mt19937_64; #endif This should be ported to Phobos. It will require some tweaks to the MersenneTwisterEngine design, as it takes more template parameters than std.random's 32-bit version. Compare Phobos, with 11 different template parameters apart from the UIntType: struct MersenneTwisterEngine(UIntType, size_t w, size_t n, size_t m, size_t r, UIntType a, size_t u, size_t s, UIntType b, size_t t, UIntType c, size_t l) with Boost (13 template parameters besides the UIntType): template<class UIntType, std::size_t w, std::size_t n, std::size_t m, std::size_t r, UIntType a, std::size_t u, UIntType d, std::size_t s, UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f> class mersenne_twister_engine See: http://www.boost.org/doc/libs/1_54_0/boost/random/mersenne_twister.hpp
Comment #1 by github-bugzilla — 2017-02-16T16:30:04Z
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>.
Comment #2 by github-bugzilla — 2017-02-24T18:15:51Z
Commit pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/45c515f267b687032b6672921d28b5c7938f6154 Add 64-bit implementation of MersenneTwisterEngine
Comment #3 by github-bugzilla — 2017-03-22T12:22:09Z
Commit pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/45c515f267b687032b6672921d28b5c7938f6154 Add 64-bit implementation of MersenneTwisterEngine