tf-random-0.5: High-quality splittable pseudorandom number generator

Copyright | (c) 2012-2013 Michał Pałka
License | BSD3
Maintainer | michal.palka@chalmers.se
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

System.Random.TF.Gen

Description

This module provides the `TFGen` generator and the alternative `RandomGen` class. `TFGen` also implements the standard `RandomGen` class.

Synopsis

- data TFGen
- class RandomGen g where
  - next :: g -> (Word32, g)
  - split :: g -> (g, g)
  - splitn :: g -> Int -> Word32 -> g
  - level :: g -> g
- seedTFGen :: (Word64, Word64, Word64, Word64) -> TFGen

# Documentation

data TFGen Source #

The generator type

#### Instances

Instances details

Read TFGen Source # |
Instance details Defined in System.Random.TF.Gen Methods readsPrec :: Int -> ReadS TFGen Source # readList :: ReadS [TFGen] Source # readPrec :: ReadPrec TFGen Source # readListPrec :: ReadPrec [TFGen] Source #
Show TFGen Source # |
Instance details Defined in System.Random.TF.Gen Methods showsPrec :: Int -> TFGen -> ShowS Source # show :: TFGen -> String Source # showList :: [TFGen] -> ShowS Source #
RandomGen TFGen Source # |

Instance details

Defined in System.Random.TF.Gen

Methods

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

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

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

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

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

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

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

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

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

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

RandomGen TFGen Source # |
Instance details Defined in System.Random.TF.Gen Methods next :: TFGen -> (Word32, TFGen) Source # split :: TFGen -> (TFGen, TFGen) Source # splitn :: TFGen -> Int -> Word32 -> TFGen Source # level :: TFGen -> TFGen Source #

class RandomGen g where Source #

Alternative `RandomGen` class with a modified `next` operation, and added `splitn` and `level` operations.

Using the generator requires that no more than one operation is called on the same generator state, as the implementation does not guarantee pseudorandomness otherwise. As an exception, calling `splitn` many times on the same generator state is allowed as long as the 'bits' argument is the same for all the calls.

Methods

next :: g -> (Word32, g) Source #

`next` returns a `Word32` that appears to have been chosen uniformly at random, and a new generator state.

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

`split` returns two derived generator states that appear to be independent pseudorandom number generators.

splitn Source #

Arguments

:: g | Original generator state.
-> Int | Number of bits that will be used to index the derived states. Must be between 0 and 32.
-> Word32 | Index of the derived state. Call to `splitn r n i` must satisfy `0 <= i < 2^n`.
-> g |

`splitn` is the n-way split operation used to create many derived generator states in one go. Application of `splitn` to two first arguments should be shared between different applications of the index argument to avoid unnecessary repeated computations.

The following code creates ten 'independent' generator states. Number '4' comes from the fact that at least four bits are needed to encode ten different indices.

       f :: RandomGen g => g -> [g]
       f r = map (splitn r 4) [0..9]

level :: g -> g Source #

`level` is a 'hint' operation that may cause an iteration of work of the generator be performed prematurely in order to prevent the subsequent operations from being expensive. It is meant to be called before a `splitn` operation, which is expected to be evaluated a very large number indices. Calling `level` in such case might decrease the total amount of work performed.

#### Instances

Instances details

RandomGen TFGen Source # |
Instance details Defined in System.Random.TF.Gen Methods next :: TFGen -> (Word32, TFGen) Source # split :: TFGen -> (TFGen, TFGen) Source # splitn :: TFGen -> Int -> Word32 -> TFGen Source # level :: TFGen -> TFGen Source #

seedTFGen :: (Word64, Word64, Word64, Word64) -> TFGen Source #

Create a generator from a random seed.