moo-1.0: Genetic algorithm library

Safe HaskellNone

Moo.GeneticAlgorithm.Random

Contents

Description

Some extra facilities to work with Rand monad and PureMT random number generator.

Synopsis

Random numbers from given range

getRandomR :: Random a => (a, a) -> Rand aSource

Yield a new randomly selected value of type a in the range (lo, hi). See randomR for details.

getRandom :: Random a => Rand aSource

Yield a new randomly selected value of type a. See random for details.

Probability distributions

getNormal2 :: Rand (Double, Double)Source

Yield two randomly selected values which follow standard normal distribution.

getNormal :: Rand DoubleSource

Yield one randomly selected value from standard normal distribution.

Random samples and shuffles

randomSample :: Int -> [a] -> Rand [a]Source

Take at most n random elements from the list. Preserve order.

shuffle :: [a] -> Rand [a]Source

Randomly reorder the list.

Building blocks

withProbability :: Double -> (a -> Rand a) -> a -> Rand aSource

Modify value with probability p. Return the unchanged value with probability 1-p.

Re-exports from random number generator packages

getInt :: Rand Int

Yield a new Int value from the generator.

getWord :: Rand Word

Yield a new Word value from the generator.

getInt64 :: Rand Int64

Yield a new Int64 value from the generator.

getWord64 :: Rand Word64

Yield a new Word64 value from the generator.

getDouble :: Rand Double

Yield a new 53-bit precise Double value from the generator.

runRandom :: Rand a -> PureMT -> (a, PureMT)

Run a random computation using the generator g, returning the result and the updated generator.

evalRandom :: Rand a -> PureMT -> a

Evaluate a random computation using the mersenne generator g. Note that the generator g is not returned, so there's no way to recover the updated version of g.

newPureMT :: IO PureMT

Create a new PureMT generator, using the clocktime as the base for the seed.

data Rand a

A basic random monad, for generating random numbers from pure mersenne twisters.

Instances

data PureMT

PureMT, a pure mersenne twister pseudo-random number generator