-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A pure Haskell PRNG. -- -- This is a psuedo-random number generator (PRNG). It is designed to -- replace the standard Haskell '98 PRNG from the random -- package. It has the following properties: -- -- -- -- The actual algorithm is a lag-4 Multiply With Carry (MWC) generator, -- using 32-bit arithmetic. (Should be fast on 32-bit and 64-bit -- platforms.) If my algebra is correct, its period should be roughly -- 1.46 * 10^48. (By constrast, random claims to have a period -- of only 2.30 * 10^18.) -- -- Note that this algorithm, by itself, is not cryptographically -- secure. -- -- Changes: -- -- @package AC-Random @version 0.1 -- | This module contains the raw random number generator algorithm. -- Usually you would import Random.MWC.Pure for a more convinient -- API. module Random.MWC.Primitive -- | An immutable random seed value for the PRNG. data Seed -- | 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. seed :: [Word32] -> Seed -- | Given an initial Seed value, return a random Word32 and -- a new Seed value. -- -- The Word32 value is chosen psuedo-randomly (i.e., the same -- Seed is guaranteed to always yield the same choice) with -- uniform distribution (i.e., all possibilities equally likely) over the -- complete range from 0x00000000 to 0xFFFFFFFF inclusive. next_word :: Seed -> (Word32, Seed) instance Eq Seed instance Ord Seed -- | Pure functions for random number generation. module Random.MWC.Pure -- | An immutable random seed value for the PRNG. data Seed -- | 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. seed :: [Word32] -> Seed -- | 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. class Bounded x => BoundedRandom x bounded_random :: BoundedRandom x => Seed -> (x, Seed) -- | 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.) class Ord x => UnitRandom x unit_random :: UnitRandom x => Seed -> (x, Seed) -- | Class of things that can be chosen at random over a specified -- interval. This requires that the type is ordered. class Ord x => RangeRandom x range_random :: RangeRandom x => (x, x) -> Seed -> (x, Seed) -- | Given a function to generate one random item, generate a list of -- random items (of the specified length). random_list :: (Seed -> (x, Seed)) -> Int -> Seed -> ([x], Seed) instance RangeRandom Word instance RangeRandom Int instance RangeRandom Int64 instance RangeRandom Int32 instance RangeRandom Int16 instance RangeRandom Int8 instance RangeRandom Word64 instance RangeRandom Word32 instance RangeRandom Word16 instance RangeRandom Word8 instance RangeRandom Double instance RangeRandom Float instance UnitRandom Double instance UnitRandom Float instance BoundedRandom Word instance BoundedRandom Int instance BoundedRandom Int64 instance BoundedRandom Int32 instance BoundedRandom Int16 instance BoundedRandom Int8 instance BoundedRandom Word64 instance BoundedRandom Word32 instance BoundedRandom Word16 instance BoundedRandom Word8 instance BoundedRandom Bool -- | 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. module Random.MWC.Monadic -- | An immutable random seed value for the PRNG. data Seed -- | The class of monads holding a single random Seed within their -- state. class Monad m => RandomM m get_random_seed :: RandomM m => m Seed set_random_seed :: RandomM m => Seed -> m () -- | 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. bounded_randomM :: (RandomM m, BoundedRandom x) => m x -- | 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. unit_randomM :: (RandomM m, UnitRandom x) => m x -- | 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. range_randomM :: (RandomM m, RangeRandom x) => (x, x) -> m x