4 ms·
Mersenne Twister
- GuB-42 6y agoMersenne Twister, why is it so popular? Is it because it has a cool name? Is it because it was the best when it came out? Now, it doesn't seem to have much for it besides its cool name. It is relatively complex, fast but not that fast, good randomness but not that good, and most importantly, it looks like there are RNGs that are better in every aspect. I used xorshifts in the past but now, PCGs seem to be the overall best. Some people praise its ridiculously long period, but at that point, it is more of a disadvantage because it requires an equally large state.
- tinus_hn 6y agoBecause it is very widely available for free and it is pretty great (good enough for most use cases) where the original solution (the c rand function) is awful. There might be better solutions but do they have about 20 good libraries ready to use for every language you can imagine? It’s a bit like qsort. It isn’t even the best but it is straightforward, widely available, free and magnitudes better than the naive bubble sort solution.
- 37ef_ced3 6y agoIf 32 bits are enough, use 32-bit PCG (https://www.pcg-random.org/ https://www.pcg-random.org/) instead In Go: package rand type Src [2]uint64 func New(bits1, bits2 uint64) *Src { return &Src{bits1, bits2 | 1} } func (s *Src) Uint32() uint32 { var ( x = s[0] y = uint32(x >> 59) z = uint32((x>>18 ^ x) >> 27) ) s[0] = s[1] + x*6364136223846793005 return z>>y | z<<(-y&31) } func (s *Src) LessThan(n uint32) uint32 { for min := -n % n; ; { r := s.Uint32() if r >= min { return r % n } } }