random-source-0.3.0.11: Generic basis for random number generators

Safe HaskellNone
LanguageHaskell2010

Data.Random.Internal.Source

Synopsis

Documentation

data Prim a where Source #

A Prompt GADT describing a request for a primitive random variate. Random variable definitions will request their entropy via these prompts, and entropy sources will satisfy those requests. The functions in Data.Random.Source.Internal.TH extend incomplete entropy-source definitions to complete ones, essentially defining a very flexible implementation-defaulting system.

Some possible future additions: PrimFloat :: Prim Float PrimInt :: Prim Int PrimPair :: Prim a -> Prim b -> Prim (a :*: b) PrimNormal :: Prim Double PrimChoice :: [(Double :*: a)] -> Prim a PrimBytes :: !Int -> Prim ByteString

Unfortunately, I cannot get Haddock to accept my comments about the data constructors, but hopefully they should be reasonably self-explanatory.

Instances
Show (Prim a) Source # 
Instance details

Defined in Data.Random.Source.Internal.Prim

Methods

showsPrec :: Int -> Prim a -> ShowS #

show :: Prim a -> String #

showList :: [Prim a] -> ShowS #

class Monad m => MonadRandom m where Source #

A typeclass for monads with a chosen source of entropy. For example, RVar is such a monad - the source from which it is (eventually) sampled is the only source from which a random variable is permitted to draw, so when directly requesting entropy for a random variable these functions are used.

Minimum implementation is either the internal getRandomPrim or all other functions. Additionally, this class's interface is subject to extension at any time, so it is very, very strongly recommended that the monadRandom Template Haskell function be used to implement this function rather than directly implementing it. That function takes care of choosing default implementations for any missing functions; as long as at least one function is implemented, it will derive sensible implementations of all others.

To use monadRandom, just wrap your instance declaration as follows (and enable the TemplateHaskell and GADTs language extensions):

$(monadRandom [d|
        instance MonadRandom FooM where
            getRandomDouble = return pi
            getRandomWord16 = return 4
            {- etc... -}
    |])

Minimal complete definition

Nothing

Methods

getRandomPrim :: Prim t -> m t Source #

Generate a random value corresponding to the specified primitive.

This is an internal interface; use at your own risk. It may change or disappear at any time.

getRandomWord8 :: m Word8 Source #

Generate a uniformly distributed random Word8

getRandomWord16 :: m Word16 Source #

Generate a uniformly distributed random Word16

getRandomWord32 :: m Word32 Source #

Generate a uniformly distributed random Word32

getRandomWord64 :: m Word64 Source #

Generate a uniformly distributed random Word64

getRandomDouble :: m Double Source #

Generate a uniformly distributed random Double in the range 0 <= U < 1

getRandomNByteInteger :: MonadRandom m => Int -> m Integer Source #

Generate a uniformly distributed random Integer in the range 0 <= U < 256^n

Instances
MonadRandom IO Source # 
Instance details

Defined in Data.Random.Source.IO

Monad m => MonadRandom (StateT PureMT m) Source # 
Instance details

Defined in Data.Random.Source.PureMT

Monad m => MonadRandom (StateT StdGen m) Source # 
Instance details

Defined in Data.Random.Source.StdGen

Monad m => MonadRandom (StateT PureMT m) Source # 
Instance details

Defined in Data.Random.Source.PureMT

Monad m => MonadRandom (StateT StdGen m) Source # 
Instance details

Defined in Data.Random.Source.StdGen

(PrimMonad m, s ~ PrimState m) => MonadRandom (ReaderT (Gen s) m) Source # 
Instance details

Defined in Data.Random.Source.MWC

(Monad m, Monoid w) => MonadRandom (RWST r w PureMT m) Source # 
Instance details

Defined in Data.Random.Source.PureMT

(Monad m, Monoid w) => MonadRandom (RWST r w StdGen m) Source # 
Instance details

Defined in Data.Random.Source.StdGen

(Monad m, Monoid w) => MonadRandom (RWST r w PureMT m) Source # 
Instance details

Defined in Data.Random.Source.PureMT

(Monad m, Monoid w) => MonadRandom (RWST r w StdGen m) Source # 
Instance details

Defined in Data.Random.Source.StdGen

class Monad m => RandomSource m s where Source #

A source of entropy which can be used in the given monad.

See also MonadRandom.

Minimum implementation is either the internal getRandomPrimFrom or all other functions. Additionally, this class's interface is subject to extension at any time, so it is very, very strongly recommended that the randomSource Template Haskell function be used to implement this function rather than directly implementing it. That function takes care of choosing default implementations for any missing functions; as long as at least one function is implemented, it will derive sensible implementations of all others.

To use randomSource, just wrap your instance declaration as follows (and enable the TemplateHaskell, MultiParamTypeClasses and GADTs language extensions, as well as any others required by your instances, such as FlexibleInstances):

$(randomSource [d|
        instance RandomSource FooM Bar where
            {- at least one RandomSource function... -}
    |])

Minimal complete definition

Nothing

Methods

getRandomPrimFrom :: s -> Prim t -> m t Source #

Generate a random value corresponding to the specified primitive.

This is an internal interface; use at your own risk. It may change or disappear at any time.

getRandomWord8From :: s -> m Word8 Source #

Generate a uniformly distributed random Word8

getRandomWord16From :: s -> m Word16 Source #

Generate a uniformly distributed random Word16

getRandomWord32From :: s -> m Word32 Source #

Generate a uniformly distributed random Word32

getRandomWord64From :: s -> m Word64 Source #

Generate a uniformly distributed random Word64

getRandomDoubleFrom :: s -> m Double Source #

Generate a uniformly distributed random Double in the range 0 <= U < 1

getRandomNByteIntegerFrom :: s -> Int -> m Integer Source #

Generate a uniformly distributed random Integer in the range 0 <= U < 256^n

Instances
RandomSource IO DevRandom Source # 
Instance details

Defined in Data.Random.Source.DevRandom

MonadRandom m => RandomSource m StdRandom Source # 
Instance details

Defined in Data.Random.Source.Std

RandomSource IO (Gen RealWorld) Source # 
Instance details

Defined in Data.Random.Source.MWC

Monad m => RandomSource m (GetPrim m) Source # 
Instance details

Defined in Data.Random.Internal.Source

Monad m => RandomSource m (m Word8) Source # 
Instance details

Defined in Data.Random.Source

Monad m => RandomSource m (m Word16) Source # 
Instance details

Defined in Data.Random.Source

Monad m => RandomSource m (m Word32) Source # 
Instance details

Defined in Data.Random.Source

Monad m => RandomSource m (m Word64) Source # 
Instance details

Defined in Data.Random.Source

Monad m => RandomSource m (m Double) Source # 
Instance details

Defined in Data.Random.Source

MonadIO m => RandomSource m (IORef PureMT) Source # 
Instance details

Defined in Data.Random.Source.PureMT

(Monad m, ModifyRef (IORef StdGen) m StdGen) => RandomSource m (IORef StdGen) Source # 
Instance details

Defined in Data.Random.Source.StdGen

(Monad m1, ModifyRef (Ref m2 PureMT) m1 PureMT) => RandomSource m1 (Ref m2 PureMT) Source # 
Instance details

Defined in Data.Random.Source.PureMT

(Monad m, ModifyRef (STRef s PureMT) m PureMT) => RandomSource m (STRef s PureMT) Source # 
Instance details

Defined in Data.Random.Source.PureMT

(Monad m, ModifyRef (STRef s StdGen) m StdGen) => RandomSource m (STRef s StdGen) Source # 
Instance details

Defined in Data.Random.Source.StdGen

(Monad m1, ModifyRef (Ref m2 StdGen) m1 StdGen) => RandomSource m1 (Ref m2 StdGen) Source # 
Instance details

Defined in Data.Random.Source.StdGen

RandomSource (ST s) (Gen s) Source # 
Instance details

Defined in Data.Random.Source.MWC

newtype GetPrim m Source #

This type provides a way to define a RandomSource for a monad without actually having to declare an instance.

Constructors

GetPrim (forall t. Prim t -> m t)