-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | random number library -- -- This package provides a basic random number generation library, -- including the ability to split random number generators. @package random @version 1.1 -- | 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: -- -- -- -- 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. module System.Random -- | The class RandomGen provides a common interface to random -- number generators. class RandomGen g -- | The next operation returns an Int that is uniformly -- distributed in the range returned by genRange (including both -- end points), and a new generator. next :: RandomGen g => g -> (Int, g) -- | The genRange operation yields the range of values returned by -- the generator. -- -- It is required that: -- -- -- -- The second condition ensures that genRange cannot examine its -- argument, and hence the value it returns can be determined only by the -- instance of RandomGen. That in turn allows an implementation to -- make a single call to genRange to establish a generator's -- range, without being concerned that the generator returned by (say) -- next might have a different range to the generator passed to -- next. -- -- The default definition spans the full range of Int. genRange :: RandomGen g => g -> (Int, Int) -- | The split operation allows one to obtain two distinct random -- number generators. This is very useful in functional programs (for -- example, when passing a random number generator down to recursive -- calls), but very little work has been done on statistically robust -- implementations of split ([System.Random\#Burton, -- System.Random\#Hellekalek] are the only examples we know of). split :: RandomGen g => g -> (g, g) -- | The StdGen instance of RandomGen has a genRange -- of at least 30 bits. -- -- The result of repeatedly using next should be at least as -- statistically robust as the Minimal Standard Random Number -- Generator described by [System.Random\#Park, -- System.Random\#Carta]. Until more is known about -- implementations of split, all we require is that split -- deliver generators that are (a) not identical and (b) independently -- robust in the sense just given. -- -- The Show and Read instances of StdGen provide a -- primitive way to save the state of a random number generator. It is -- required that read (show g) == g. -- -- In addition, reads may be used to map an arbitrary string (not -- necessarily one produced by show) onto a value of type -- StdGen. In general, the Read instance of StdGen -- has the following properties: -- -- data 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. mkStdGen :: Int -> StdGen -- | 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 -- gets a random integer between 1 and 6: -- --
--   rollDice :: IO Int
--   rollDice = getStdRandom (randomR (1,6))
--   
getStdRandom :: (StdGen -> (a, StdGen)) -> IO a -- | Gets the global random number generator. getStdGen :: IO StdGen -- | Sets the global random number generator. setStdGen :: StdGen -> IO () -- | Applies split to the current global random generator, updates -- it with one of the results, and returns the other. newStdGen :: IO StdGen -- | With a source of random number supply in hand, the Random class -- allows the programmer to extract random values of a variety of types. -- -- Minimal complete definition: randomR and random. class Random a -- | Takes a range (lo,hi) and a random number generator g, -- and returns a random value uniformly distributed in the closed -- interval [lo,hi], together with a new generator. It is -- unspecified what happens if lo>hi. For continuous types -- there is no requirement that the values lo and hi are -- ever produced, but they may be, depending on the implementation and -- the interval. randomR :: (Random a, RandomGen g) => (a, a) -> g -> (a, g) -- | The same as randomR, but using a default range determined by -- the type: -- -- random :: (Random a, RandomGen g) => g -> (a, g) -- | Plural variant of randomR, producing an infinite list of random -- values instead of returning a new generator. randomRs :: (Random a, RandomGen g) => (a, a) -> g -> [a] -- | Plural variant of random, producing an infinite list of random -- values instead of returning a new generator. randoms :: (Random a, RandomGen g) => g -> [a] -- | A variant of randomR that uses the global random number -- generator (see System.Random#globalrng). randomRIO :: Random a => (a, a) -> IO a -- | A variant of random that uses the global random number -- generator (see System.Random#globalrng). randomIO :: Random a => IO a instance System.Random.Random GHC.Integer.Type.Integer instance System.Random.Random GHC.Types.Int instance System.Random.Random GHC.Int.Int8 instance System.Random.Random GHC.Int.Int16 instance System.Random.Random GHC.Int.Int32 instance System.Random.Random GHC.Int.Int64 instance System.Random.Random GHC.Types.Word instance System.Random.Random GHC.Word.Word8 instance System.Random.Random GHC.Word.Word16 instance System.Random.Random GHC.Word.Word32 instance System.Random.Random GHC.Word.Word64 instance System.Random.Random Foreign.C.Types.CChar instance System.Random.Random Foreign.C.Types.CSChar instance System.Random.Random Foreign.C.Types.CUChar instance System.Random.Random Foreign.C.Types.CShort instance System.Random.Random Foreign.C.Types.CUShort instance System.Random.Random Foreign.C.Types.CInt instance System.Random.Random Foreign.C.Types.CUInt instance System.Random.Random Foreign.C.Types.CLong instance System.Random.Random Foreign.C.Types.CULong instance System.Random.Random Foreign.C.Types.CPtrdiff instance System.Random.Random Foreign.C.Types.CSize instance System.Random.Random Foreign.C.Types.CWchar instance System.Random.Random Foreign.C.Types.CSigAtomic instance System.Random.Random Foreign.C.Types.CLLong instance System.Random.Random Foreign.C.Types.CULLong instance System.Random.Random Foreign.C.Types.CIntPtr instance System.Random.Random Foreign.C.Types.CUIntPtr instance System.Random.Random Foreign.C.Types.CIntMax instance System.Random.Random Foreign.C.Types.CUIntMax instance System.Random.Random GHC.Types.Char instance System.Random.Random GHC.Types.Bool instance System.Random.Random GHC.Types.Double instance System.Random.Random GHC.Types.Float instance System.Random.Random Foreign.C.Types.CFloat instance System.Random.Random Foreign.C.Types.CDouble instance System.Random.RandomGen System.Random.StdGen instance GHC.Show.Show System.Random.StdGen instance GHC.Read.Read System.Random.StdGen