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

Copyright(c) 2012-2013 Michał Pałka
LicenseBSD3
Maintainermichal.palka@chalmers.se
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

System.Random.TF.Gen

Description

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

Synopsis

Documentation

data TFGen #

The generator type

class RandomGen g where #

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.

Minimal complete definition

next, split, splitn, level

Methods

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

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

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

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

splitn :: g -> Int -> Word32 -> 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 #

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

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

Create a generator from a random seed.