24 ms·
Initializing the mersenne twister is really hard: https://github.com/PetterS/monolith/blob/master/minimum/core/random.h https://github.com/PetterS/monolith/blob
by petters 8y ago
Initializing the mersenne twister is really hard: https://github.com/PetterS/monolith/blob/master/minimum/core/random.h https://github.com/PetterS/monolith/blob/master/minimum/core...
Edit: There are two links in the code with more info.
- dearrifling 8y agoOne shouldn't std::move in a return. Returning a local is already automatically an rvalue, however explicitly moving it disables copy elision.
- petters 8y agoYou are completely right. That should be fixed
- netheril96 8y agoMost other random libraries, in whatever languages, do not even offer the option of this "right" version of initialization. They all just seed with a 32-bit integer. If you are content with those libraries, you should be content with a simple `std::mt19937{std::random_device{}()}`.
- whyever 8y agoI don't think this is true for modern languages. Rust seeds the whole state by default: https://docs.rs/rand/0.6.5/rand/ https://docs.rs/rand/0.6.5/rand/ Julia seems to seed 128 bits: https://github.com/JuliaLang/julia/blob/5741c7f53c5ea443bbd73cc5157b83de415c6d1b/stdlib/Random/src/RNGs.jl#L249 https://github.com/JuliaLang/julia/blob/5741c7f53c5ea443bbd7... However, your statement seems to apply to old languages: C# uses only 32 bits and the time for seeding: https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.random?vi... Java only supports 48 bit seeds: https://docs.oracle.com/javase/8/docs/api/java/util/Random.html https://docs.oracle.com/javase/8/docs/api/java/util/Random.h...
- madisfun 8y agoMersenne Twister has a huge state, and if you have to use the MT (you need a very long period), you will probably want to be able to initialize it properly. For the common use case is a linear congruential generator which is initialized with just one integer.
- GoblinSlayer 8y agoHuh? You can't possibly need a period 2^19937-1.