AC-Random-0.1: A pure Haskell PRNG.

Random.MWC.Monadic

Contents

Description

Monadic functions for random number generation.

Because manually threading the correct Seed value around is tedious and error-prone, one common approach is to use some kind of state monad to hide it. This module provides the convenience functions to make this easy; just write a RandomM instance for your particular monad, and then you can easily and conveniently generate random numbers.

Synopsis

Random seed

data Seed Source

An immutable random seed value for the PRNG.

Instances

Random monads

class Monad m => RandomM m whereSource

The class of monads holding a single random Seed within their state.

Methods

get_random_seed :: m SeedSource

Fetch the current Seed value.

set_random_seed :: Seed -> m ()Source

Replace the current Seed value.

Monadic operations

bounded_randomM :: (RandomM m, BoundedRandom x) => m xSource

The monadic analogue of bounded_random.

Return a value randomly chosen between minBound and maxBound. Uses the current Seed value from within the monad, automatically updating said seed value in the process. Thus, repeatedly calling this function will yield different successive values.

unit_randomM :: (RandomM m, UnitRandom x) => m xSource

The monadic analogue of unit_random.

Returns a value randomly chosen between "zero" and "one". Uses the current Seed value from within the monad, automatically updating said seed value in the process. Thus, repeatedly calling this function will yield different successive values.

range_randomM :: (RandomM m, RangeRandom x) => (x, x) -> m xSource

The monadic analogue of range_random.

Returns a value randomly chosen from a user-specified range (inclusive). Uses the current Seed value from within the monad, automatically updating said seed value in the process. Thus, repeatedly calling this function will yield different successive values.