Rand Monad and Random Class #
This module provides tools for formulating computations guided by randomness and for defining objects that can be created randomly.
Main definitions #
RandTandRandGTmonad transformers for computations guided by randomness;RandandRandGmonads as special cases of the aboveRandomclass for objects that can be generated randomly;randomto generate one object;
BoundedRandomclass for objects that can be generated randomly inside a range;randomRto generate one object inside a range;
IO.runRandto run a randomized computation inside any monad that has access tostdGenRef.
References #
- Similar library in Haskell: https://hackage.haskell.org/package/MonadRandom
Random m α gives us machinery to generate values of type α in the monad m.
Note that m is a parameter as some types may only be sampleable with access to a certain monad.
Sample an element of this type from the provided generator.
Instances
Equations
Equations
instance
Random.instBoundedRandomFin
{m : Type → Type u_1}
[Monad m]
{n : ℕ}
:
BoundedRandom m (Fin n)
Equations
instance
Random.instBoundedRandomULiftOfULiftableOfMonad
{m : Type u → Type u_1}
{m' : Type (max v u) → Type u_2}
{α : Type u}
[Preorder α]
[ULiftable m m']
[BoundedRandom m α]
[Monad m']
:
BoundedRandom m' (ULift.{v, u} α)
Equations
def
IO.runRand
{m : Type u_1 → Type u_2}
{m₀ : Type → Type}
[Monad m]
[MonadLiftT (ST RealWorld) m₀]
[ULiftable m₀ m]
{α : Type u_1}
(cmd : RandT m α)
:
m α
Execute RandT m α using the global stdGenRef as RNG.
Note that:
stdGenRefis not necessarily properly seeded on program startup as of now and will therefore be deterministic.stdGenRefis not thread local, hence two threads accessing it at the same time will get the exact same generator.