hedgehog-1.5: Release with confidence.

Safe Haskell | None
Language | Haskell2010

Hedgehog.Internal.Seed

Contents

- Internal

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.

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

- data Seed = Seed {
  - seedValue :: !Word64
  - seedGamma :: !Word64
  }
- random :: MonadIO m => m Seed
- from :: Word64 -> Seed
- split :: Seed -> (Seed, Seed)
- nextInteger :: Integer -> Integer -> Seed -> (Integer, Seed)
- nextDouble :: Double -> Double -> Seed -> (Double, Seed)
- goldenGamma :: Word64
- nextWord64 :: Seed -> (Word64, Seed)
- nextWord32 :: Seed -> (Word32, Seed)
- mix64 :: Word64 -> Word64
- mix64variant13 :: Word64 -> Word64
- mix32 :: Word64 -> Word32
- mixGamma :: Word64 -> Word64
- global :: IORef Seed

# Documentation

data Seed Source #

A splittable random number generator.

Constructors

Seed |

Fields

- seedValue :: !Word64
- seedGamma :: !Word64

  must be an odd number

#### Instances

Instances details

Read Seed Source # |
Instance details Defined in Hedgehog.Internal.Seed Methods readsPrec :: Int -> ReadS Seed Source # readList :: ReadS [Seed] Source # readPrec :: ReadPrec Seed Source # readListPrec :: ReadPrec [Seed] Source #
Show Seed Source # |
Instance details Defined in Hedgehog.Internal.Seed Methods showsPrec :: Int -> Seed -> ShowS Source # show :: Seed -> String Source # showList :: [Seed] -> ShowS Source #
Eq Seed Source # |
Instance details Defined in Hedgehog.Internal.Seed Methods (==) :: Seed -> Seed -> Bool Source # (/=) :: Seed -> Seed -> Bool Source #
Ord Seed Source # |
Instance details Defined in Hedgehog.Internal.Seed Methods compare :: Seed -> Seed -> Ordering Source # (<) :: Seed -> Seed -> Bool Source # (<=) :: Seed -> Seed -> Bool Source # (>) :: Seed -> Seed -> Bool Source # (>=) :: Seed -> Seed -> Bool Source # max :: Seed -> Seed -> Seed Source # min :: Seed -> Seed -> Seed Source #
RandomGen Seed Source # |

Instance details

Defined in Hedgehog.Internal.Seed

Methods

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

genWord8 :: Seed -> (Word8, Seed) Source #

genWord16 :: Seed -> (Word16, Seed) Source #

genWord32 :: Seed -> (Word32, Seed) Source #

genWord64 :: Seed -> (Word64, Seed) Source #

genWord32R :: Word32 -> Seed -> (Word32, Seed) Source #

genWord64R :: Word64 -> Seed -> (Word64, Seed) Source #

genShortByteString :: Int -> Seed -> (ShortByteString, Seed) Source #

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

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

Lift Seed Source # |
Instance details Defined in Hedgehog.Internal.Seed Methods lift :: Quote m => Seed -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Seed -> Code m Seed Source #

random :: MonadIO m => m Seed Source #

Create a random `Seed` using an effectful source of randomness.

from :: Word64 -> Seed Source #

Create a `Seed` using a `Word64`.

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 :: Word64 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.

nextWord64 :: Seed -> (Word64, Seed) Source #

Generate a random `Word64`.

nextWord32 :: Seed -> (Word32, Seed) Source #

Generate a random `Word32`.

mix64 :: Word64 -> Word64 Source #

mix64variant13 :: Word64 -> Word64 Source #

mix32 :: Word64 -> Word32 Source #

mixGamma :: Word64 -> Word64 Source #

global :: IORef Seed Source #