Random.MWC.Pure

Contents

Description

Pure functions for random number generation.

Synopsis

# Random seed

data Seed Source

An immutable random seed value for the PRNG.

Instances

 Eq Seed Ord Seed

seed :: [Word32] -> SeedSource

Create a new random seed value from the supplied list of `Word32` values. If the list is empty, return a default, hard-coded value. Otherwise, every element of the list affects the result. The list must be finite; the function will loop forever othewise.

# Random number generation

class Bounded x => BoundedRandom x whereSource

Class of things that can be chosen at random over their entire value range. This requires that the range of possible values is actually limited.

Methods

bounded_random :: Seed -> (x, Seed)Source

Given a `Seed`, return a randomly-chosen value and a new `Seed` value.

The value is chosen psuedo-randomly (the same `Seed` will always yield the same choice), with uniform distribution (all values equally likely). The range of possible values is from `minBound` to `maxBound` inclusive.

class Ord x => UnitRandom x whereSource

Class of things that can be chosen at random over the interval from zero to one. This requires that "zero" and "one" are meaningful concepts for this type, and also that the type is ordered. (Also, there must be values between zero and one, which rules out integral types.)

Methods

unit_random :: Seed -> (x, Seed)Source

Given a `Seed`, return a randomly-chosen value and a new `Seed` value.

The value is chosen psuedo-randomly (the same `Seed` will always yield the same choice), with uniform distribution (all values equally likely). The range of possible values is from "zero" to "one" inclusive.

Instances

 UnitRandom Double UnitRandom Float

class Ord x => RangeRandom x whereSource

Class of things that can be chosen at random over a specified interval. This requires that the type is ordered.

Methods

range_random :: (x, x) -> Seed -> (x, Seed)Source

Given a `Seed`, return a randomly-chosen value and a new `Seed` value.

The value is chosen psuedo-randomly (the same `Seed` will always yield the same choice), with uniform distribution (all values equally likely). The range is given by the first argument, which specifies the lower and upper bounds (inclusive).

random_list :: (Seed -> (x, Seed)) -> Int -> Seed -> ([x], Seed)Source

Given a function to generate one random item, generate a list of random items (of the specified length).