Recent

Author Topic: Replace Mersenne Twister PRNG?  (Read 613 times)

segfault

  • Full Member
  • ***
  • Posts: 104
Replace Mersenne Twister PRNG?
« on: April 27, 2020, 10:28:59 am »
FP currently uses the Mersenne Twister random number generator, which although commonly used, has disadvantages :

https://en.wikipedia.org/wiki/Mersenne_Twister#Disadvantages

A suggested alternative is the ACORN family of PRNG's, which is apparently easy to code, fast, and has better statistical properties than the Mersenne twister (it passes the tests which twister fails).

Wiki page :

https://en.wikipedia.org/wiki/ACORN_(PRNG)

Also the authors web site :

http://acorn.wikramaratna.org/index.html

Note : it's not cryptographically secure, but neither is the twister.
« Last Edit: April 27, 2020, 10:31:00 am by segfault »

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: Replace Mersenne Twister PRNG?
« Reply #1 on: April 27, 2020, 12:17:01 pm »
There already many alternatives (see the wiki) but if I can find C sources I will add it, depending on licensing,
ETA The period is rather low compared to others. I wonder if it really adds something.

https://wiki.freepascal.org/Marsaglia%27s_pseudo_random_number_generators (these are really fast). I added tests fror correctness.
https://wiki.freepascal.org/Delphi_compatible_LCG_Random
https://wiki.freepascal.org/Dev_random

Note that FPC is not likely to change its default random because it would break existing code and data.
Same goes for Delphi, therefor I added a Delphi compatible LCG to the wiki to be able to work with Delphi generated data.
Note I already have a pluggable framework like C++, but I need to verify some modules. Comes later this year.
« Last Edit: April 27, 2020, 12:51:02 pm by Thaddy »

BeniBela

  • Hero Member
  • *****
  • Posts: 761
    • homepage
Re: Replace Mersenne Twister PRNG?
« Reply #2 on: April 27, 2020, 12:50:13 pm »
I have implemented xoshiro**: https://github.com/benibela/internettools/blob/master/data/xquery.internals.rng.pas

The inventor of this prng claims it is faster than others

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: Replace Mersenne Twister PRNG?
« Reply #3 on: April 27, 2020, 12:54:09 pm »
Have have implemented that too (128). It is faster than most with nice properties.
It also belongs to the Marsalia family in the sense that it uses the same concepts: it derives from xorshift.
I may add it to the Marsalia article.

 

TinyPortal © 2005-2018