| ||||||||||||||||||||||||||

| ||||||||||||||||||||||||||

| ||||||||||||||||||||||||||

Description | ||||||||||||||||||||||||||

This library deals with the common task of pseudo-random number generation. The library makes it possible to generate repeatable results, by starting with a specified initial random number generator, or to get different results on each run by using the system-initialised generator or by supplying a seed from some other source. The library is split into two layers: - A core
*random number generator*provides a supply of bits. The class`RandomGen`provides a common interface to such generators. The library provides one instance of`RandomGen`, the abstract data type`StdGen`. Programmers may, of course, supply their own instances of`RandomGen`. - The class
`Random`provides a way to extract values of a particular type from a random number generator. For example, the`Float`instance of`Random`allows one to generate random values of type`Float`.
This implementation uses the Portable Combined Generator of L'Ecuyer [System.Random#LEcuyer] for 32-bit computers, transliterated by Lennart Augustsson. It has a period of roughly 2.30584e18. | ||||||||||||||||||||||||||

Synopsis | ||||||||||||||||||||||||||

| ||||||||||||||||||||||||||

Random number generators | ||||||||||||||||||||||||||

class RandomGen g where | ||||||||||||||||||||||||||

| ||||||||||||||||||||||||||

Standard random number generators | ||||||||||||||||||||||||||

data StdGen | ||||||||||||||||||||||||||

| ||||||||||||||||||||||||||

mkStdGen :: Int -> StdGen | ||||||||||||||||||||||||||

The function mkStdGen provides an alternative way of producing an initial
generator, by mapping an Int into a generator. Again, distinct arguments
should be likely to produce distinct generators.
| ||||||||||||||||||||||||||

The global random number generator | ||||||||||||||||||||||||||

There is a single, implicit, global random number generator of type
| ||||||||||||||||||||||||||

getStdRandom :: (StdGen -> (a, StdGen)) -> IO a | ||||||||||||||||||||||||||

Uses the supplied function to get a value from the current global
random generator, and updates the global generator with the new generator
returned by the function. For example, rollDice :: IO Int rollDice = getStdRandom (randomR (1,6)) | ||||||||||||||||||||||||||

getStdGen :: IO StdGen | ||||||||||||||||||||||||||

Gets the global random number generator. | ||||||||||||||||||||||||||

setStdGen :: StdGen -> IO () | ||||||||||||||||||||||||||

Sets the global random number generator. | ||||||||||||||||||||||||||

newStdGen :: IO StdGen | ||||||||||||||||||||||||||

Applies split to the current global random generator,
updates it with one of the results, and returns the other.
| ||||||||||||||||||||||||||

Random values of various types | ||||||||||||||||||||||||||

class Random a where | ||||||||||||||||||||||||||

| ||||||||||||||||||||||||||

References | ||||||||||||||||||||||||||

1. FW Burton and RL Page, 2. SK Park, and KW Miller, /Random number generators - good ones are hard to find/, Comm ACM 31(10), Oct 1988, pp1192-1201. 3. DG Carta, /Two fast implementations of the minimal standard random number generator/, Comm ACM, 33(1), Jan 1990, pp87-88. 4. P Hellekalek, 5. Pierre L'Ecuyer, /Efficient and portable combined random number generators/, Comm ACM, 31(6), Jun 1988, pp742-749. The Web site http://random.mat.sbg.ac.at/ is a great source of information. | ||||||||||||||||||||||||||

Produced by Haddock version 2.3.0 |