Random number generator for Elm

License: BSD-3-Clause

Language: Elm

Random.Pcg for Elm

"The generation of random numbers is too important to be left to chance." – Robert R. Coveyou

An alternate random number generator built around four principles:

  • Statistical Quality. If you use any seed less than 53,668 and generate one bool, it will be True – if you're using core's Random module. More sophisticated statistical tests spot patterns in the "random" numbers almost immediately. Would you want to trust the accuracy of your fuzz tests to such a flawed algorithm? This library produces far less predictable and biased output, especially if you use thousands of random numbers. See test/dieharder for more details.

  • Useful features. This library exports constant and andMap, which are conspicuously absent from core, along with other helpful functions for composing generators. Particularly interesting is independentSeed, which allows for lazy lists and isolated components to generate as much randomness as they need, when they need it.

  • Performance. This library will generate floats about 3.5 times faster than core, and ints do not regress. These figures stand to improve pending some optimizations to the compiler. You can see the full benchmark results.

  • Compatibility. This library is a drop-in replacement for core's Random module. Specifically, you can replace import Random with import Random.Pcg as Random and everything will continue to work. (The one exception is third party libraries like elm-random-extra.)

This is an implementation of PCG by M. E. O'Neil. The generator is not cryptographically secure.

Please report bugs, feature requests, and other issues on GitHub.

Changelog (major versions only)


  • Argument order of andMap flipped.


  • Upgraded for 0.18.
  • Argument order of andThen flipped.


  • Change implementation to use the RXS-M-SH variant of PCG. Now much faster and not much worse statistically.
  • Remove initialSeed2, since there are now only 32 bits of state.
  • Random.Pcg.Interop.fission has been changed to a (core) generator of (PCG) seeds.
  • Add generate to match core 4.x API. Implemented by Richard Feldman.


  • Upgraded for 0.17.
  • generate renamed step to match core 4.x API.
  • Module renamed Random.Pcg from Random.PCG.
  • split has been removed; use independentSeed.
  • minInt and maxInt values changed to match core.

Project Statistics

Sourcerank 11
Repository Size 185 KB
Stars 29
Forks 6
Watchers 2
Open issues 1
Dependencies 8
Contributors 5
Tags 19
Last updated
Last pushed

Top Contributors See all

Max Goldstein Ian Mackenzie Ilias Van Peer Nick Hollon Frank Schmitt

Packages Referencing this Repo

A faster, more featureful, statistically better, & compatible random generator
Latest release 5.0.2 - Updated - 29 stars

Recent Tags See all

5.0.2 October 01, 2017
5.0.1 July 28, 2017
5.0.0 March 16, 2017
4.0.2 November 03, 2016
4.0.1 November 01, 2016
4.0.0 October 14, 2016
3.0.4 September 29, 2016
3.0.3 September 10, 2016
3.0.2 September 08, 2016
3.0.1 August 16, 2016
3.0.0 August 03, 2016
2.1.1 June 10, 2016
2.1.0 May 31, 2016
2.0.0 May 10, 2016
1.4.0 March 18, 2016

Something wrong with this page? Make a suggestion

Last synced: 2017-10-09 10:25:20 UTC

Login to resync this repository