hedgehog-0.3: Hedgehog will eat all your bugs.

Safe HaskellNone
LanguageHaskell98

Hedgehog.Internal.Seed

Contents

Description

This is a port of "Fast Splittable Pseudorandom Number Generators" by Steele et. al. [1].

The paper's algorithm provides decent randomness for most purposes but sacrifices cryptographic-quality randomness in favor of speed. The original implementation is tested with DieHarder and BigCrush; see the paper for details.

This implementation, originally from [2], is a port from the paper.

It also takes in to account the SplittableRandom.java source code in OpenJDK v8u40-b25 as well as splittable_random.ml in Jane Street's standard library overlay (kernel) v113.33.03, and Random.fs in FsCheck v3.

Other than the choice of initial seed for from this port should be faithful. Currently, we have not rerun the DieHarder, or BigCrush tests on this implementation.

  1. Guy L. Steele, Jr., Doug Lea, Christine H. Flood Fast splittable pseudorandom number generators Comm ACM, 49(10), Oct 2014, pp453-472.
  2. Nikos Baxevanis https://github.com/moodmosaic/SplitMix/blob/master/SplitMix.hs

Synopsis

Documentation

data Seed Source #

A splittable random number generator.

Constructors

Seed 

Fields

Instances

Eq Seed Source # 

Methods

(==) :: Seed -> Seed -> Bool #

(/=) :: Seed -> Seed -> Bool #

Ord Seed Source # 

Methods

compare :: Seed -> Seed -> Ordering #

(<) :: Seed -> Seed -> Bool #

(<=) :: Seed -> Seed -> Bool #

(>) :: Seed -> Seed -> Bool #

(>=) :: Seed -> Seed -> Bool #

max :: Seed -> Seed -> Seed #

min :: Seed -> Seed -> Seed #

Read Seed Source # 
Show Seed Source # 

Methods

showsPrec :: Int -> Seed -> ShowS #

show :: Seed -> String #

showList :: [Seed] -> ShowS #

RandomGen Seed Source # 

Methods

next :: Seed -> (Int, Seed) #

genRange :: Seed -> (Int, Int) #

split :: Seed -> (Seed, Seed) #

random :: MonadIO m => m Seed Source #

Create a random Seed using an effectful source of randomness.

from :: Int64 -> Seed Source #

Create a Seed using an Int64.

split :: Seed -> (Seed, Seed) Source #

Splits a random number generator in to two.

nextInteger :: Integer -> Integer -> Seed -> (Integer, Seed) Source #

Generate a random Integer in the [inclusive,inclusive] range.

nextDouble :: Double -> Double -> Seed -> (Double, Seed) Source #

Generate a random Double in the [inclusive,exclusive) range.

Internal

These functions are exported in case you need them in a pinch, but are not part of the public API and may change at any time, even as part of a minor update.

goldenGamma :: Int64 Source #

A predefined gamma value's needed for initializing the "root" instances of Seed. That is, instances not produced by splitting an already existing instance.

We choose: the odd integer closest to 2^64/φ, where φ = (1 + √5)/2 is the golden ratio.

nextInt64 :: Seed -> (Int64, Seed) Source #

Generate a random Int64.

nextInt32 :: Seed -> (Int32, Seed) Source #

Generate a random Int32.