Pseudo-random number generation
|LTS Haskell 20.16:||22.214.171.124|
|Stackage Nightly 2023-03-31:||126.96.36.199|
|Latest on Hackage:||188.8.131.52|
Module documentation for 184.108.40.206
The Haskell Standard Library
Random Number Generation
This library provides a basic interface for (splittable) pseudo-random number generators.
The API documentation can be found here:
An older version of this library is included with GHC in
haskell98 package. This newer version is included in the Haskell
Please report bugs in the GitHub issue tracker (no longer in the GHC trac).
- Fix support for ghc-9.2 #99
- Fix performance regression for ghc-9.0 #101
- Ensure that default implementation of
ShortByteStringgeneration uses unpinned memory. #116
- Fix #54 with
#68 - if exactly one value in the
range of floating point is infinite, then
randomRreturns that value.
- Add default implementation of
- Addition of
- Addition of tuple instances for
Randomup to 7-tuple #72
- Breaking change which mostly maintains backwards compatibility, see “Breaking Changes” below.
- Support for monadic generators e.g. mwc-random.
- Monadic adapters for pure generators (providing a uniform monadic interface to pure and monadic generators).
- Faster in all cases except one by more than x18 (N.B. x18 not 18%) and some cases (depending on the type) faster by more than x1000 - see below for benchmarks.
- Passes a large number of random number test suites:
- TestU01 (SmallCrush, Crush, BigCrush)
- See random-quality for details on how to do this yourself.
- Better quality split as judged by these tests. Again see random-quality for details on how to do this yourself.
- Unbiased generation of ranges.
- Updated tests and benchmarks.
- Continuous integration.
Version 1.2.0 introduces these breaking changes:
base >= 4.8(GHC-7.10)
StdGenis no longer an instance of
randomRIOwere extracted from the
Randomclass into separate functions
In addition, there may be import clashes with new functions, e.g.
Version 1.2.0 introduces
genWord32 and similar methods to the
RandomGen class. The significantly slower method
next and its companion
genRange are now deprecated.
|25||The seeds generated by split are not independent||Fixed: changed algorithm to SplitMix, which provides a robust split operation|
|26||Add Random instances for tuples||Addressed: added
|44||Add Random instance for Natural||Addressed: added UniformRange instance for Natural|
|51||Very low throughput||Fixed: see benchmarks below|
|53||incorrect distribution of randomR for floating-point numbers||(*)|
|55||System/Random.hs:43:1: warning: [-Wtabs]||Fixed: No more tabs|
|58||Why does random for Float and Double produce exactly 24 or 53 bits?||(*)|
|59||read :: StdGen fails for strings longer than 6||Addressed: StdGen is no longer an instance of Read|
(*) 1.2 samples more bits but does not sample every
Double. There are methods to do this but they have some downsides;
see here for a
Here are some benchmarks run on a 3.1 GHz Intel Core i7. The full
benchmarks can be run using e.g.
stack bench. The benchmarks are
measured in milliseconds per 100,000 generations. In some cases, the
performance is over x1000 times better; the minimum performance
increase for the types listed below is more than x36.
|Name||1.1 Mean||1.2 Mean|
- breaking change to
randomIValIntegerto improve RNG quality and performance see https://github.com/haskell/random/pull/4 and ghc https://ghc.haskell.org/trac/ghc/ticket/8898
- correct documentation about generated range of Int32 sized values of type Int https://github.com/haskell/random/pull/7
- fix memory leaks by using strict fields and strict atomicModifyIORef’ https://github.com/haskell/random/pull/8 related to ghc trac tickets #7936 and #4218
- support for base < 4.6 (which doesnt provide strict atomicModifyIORef’) and integrating Travis CI support. https://github.com/haskell/random/pull/12
- fix C type in test suite https://github.com/haskell/random/pull/9
bump for overflow bug fixes
bump for ticket 8704, build fusion
bump for bug fixes,
bumped version for float/double range bugfix