idontgetoutmuch / random

Random number library
Other
3 stars 2 forks source link

Coordination: changes to PRNG libraries #23

Open curiousleo opened 4 years ago

curiousleo commented 4 years ago

To avoid duplication of work, let's track work we've done to make PRNG libraries compatible with the interface-to-performance branch here.

Feel free to edit this description directly.


splitmix: https://github.com/lehins/splitmix/tree/new-random (diff)


pcgen: https://github.com/curiousleo/pcgen/tree/new-random (diff)


mwc-random: WIP https://github.com/curiousleo/mwc-random/tree/random-v1.2-compat (diff)


random-fu: does not depend on random; uses random-source to abstract over concrete PRNGs


QuickCheck: builds with StdGen from random v1.1 on non-GHC platforms. That won't work with random v1.2.


hedgehog: requires instance UniformRange Integer which is currently missing.

curiousleo commented 4 years ago

https://github.com/bos/mwc-random/compare/master...curiousleo:random-v1.2-compat?expand=1 fails to build with

mwc-random/System/Random/MWC.hs:414:28: error:  
    Multiple declarations of ‘Seed’  
    Declared at: System/Random/MWC.hs:389:16  
                 System/Random/MWC.hs:414:28  
    |  
414 |   newtype Frozen (Gen s) = Seed  
    |                            ^^^^  

I don't know how to fix that.

lehins commented 4 years ago

@curiousleo It is a newtype, so you need to wrap with a constructor.

curiousleo commented 4 years ago

@curiousleo It is a newtype, so you need to wrap with a constructor.

Fixed. Thanks!

idontgetoutmuch commented 4 years ago

Should we close this or use it to track

lehins commented 4 years ago

Alright gentleman, I implemented some benchmarks for all pure RNGs available in Haskell and results are pretty impressive. Here is a PR and a branch that you can use to run benchmarks for both random-1.1 and random-1.2: lehins/haskell-benchmarks#7

Here are also all the repo's with fixed RandomGen instances:

It is pretty cool that changes were incredibly minimal and all of them are backwards compatible.

To run benchmarks:

$ cd haskell-benchmarks/new-random-benchmarks/
$ stack bench --ba '--output old-random-word16.html --match prefix Pure/Word16' --stack-yaml stack-old-random.yaml
$ stack bench --ba '--output new-random-word16.html --match prefix Pure/Word16'

And so on for other types. (It's possible to run them all at once, but I find the plots bit noisy that way)

Next in line are stateful RNGs, but those I think I'll do some time later.

curiousleo commented 4 years ago

Alright gentleman, I implemented some benchmarks for all pure RNGs available in Haskell and results are pretty impressive. Here is a PR and a branch that you can use to run benchmarks for both random-1.1 and random-1.2: lehins/haskell-benchmarks#7

Here are also all the repo's with fixed RandomGen instances:

* [lehins/Xorshift#1](https://github.com/lehins/Xorshift/pull/1)

* [lehins/mersenne-random-pure64#1](https://github.com/lehins/mersenne-random-pure64/pull/1)

* [lehins/tf-random#1](https://github.com/lehins/tf-random/pull/1)

* [lehins/pcg-random#1](https://github.com/lehins/pcg-random/pull/1)

* [lehins/pcgen#1](https://github.com/lehins/pcgen/pull/1)

It is pretty cool that changes were incredibly minimal and all of them are backwards compatible.

This is fantastic!

Next in line are stateful RNGs, but those I think I'll do some time later.

I would also be interested in benchmarks for uniformRM since we put a lot of effort into optimising the range algorithms.