Random variables. An RVar is a sampleable random variable. Because
probability distributions form a monad, they are quite easy to work with
in the standard Haskell monadic styles. For examples, see the source for
any of the Distribution instances - they all are defined in terms of
RVars.

Documentation

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):

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):

A random variable with access to operations in an underlying monad. Useful
examples include any form of state for implementing random processes with hysteresis,
or writer monads for implementing tracing of complicated algorithms.

For example, a simple random walk can be implemented as an RVarTIO value:

The ability to lift is very important - without it, every RVar would have
to either be given access to the full capability of the monad in which it
will eventually be sampled (which, incidentally, would also have to be
monomorphic so you couldn't sample one RVar in more than one monad)
or functions manipulating RVars would have to use higher-ranked
types to enforce the same kind of isolation and polymorphism.