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.

- data Seed
- class Monad m => RandomM m where
- get_random_seed :: m Seed
- set_random_seed :: Seed -> m ()

- bounded_randomM :: (RandomM m, BoundedRandom x) => m x
- unit_randomM :: (RandomM m, UnitRandom x) => m x
- range_randomM :: (RandomM m, RangeRandom x) => (x, x) -> m x

# Random seed

# Random monads

class Monad m => RandomM m whereSource

The class of monads holding a single random `Seed`

within their
state.

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.