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;
runRandto run a randomized computation inside any monad that has access tostdGenRef.
References #
- Similar library in Haskell: https://hackage.haskell.org/package/MonadRandom
@[reducible, inline]
A monad to generate random objects using the generator type g.
Equations
Instances For
@[reducible, inline]
A monad to generate random objects using the generator type StdGen.
Equations
Instances For
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.
Generate a value of type
αrandomly using generatorg.
Instances
@[inline]
def
Plausible.RandT.up
{α : Type u}
{m : Type u → Type w}
{m' : Type (max u v) → Type w'}
{g : Type}
[RandomGen g]
[Monad m]
[Monad m']
(m_up : {α : Type u} → m α → m' (ULift α))
(x : RandGT g m α)
:
Given a random generator for α, we can convert it to a random generator for ULift α.
Equations
Instances For
@[inline]
def
Plausible.RandT.down
{α : Type u}
{m : Type (max u v) → Type w}
{m' : Type u → Type w'}
{g : Type}
[RandomGen g]
[Monad m]
[Monad m']
(m_down : {α : Type u} → m (ULift α) → m' α)
(x : RandGT g m (ULift α))
:
RandGT g m' α
Given a random generator for ULift α, we can convert it to a random generator for α.
Equations
Instances For
Equations
Equations
instance
Plausible.Random.instBoundedRandomFin
{m : Type → Type u_1}
[Monad m]
{n : Nat}
:
BoundedRandom m (Fin n)
Equations
instance
Plausible.Random.instBoundedRandomBitVec
{m : Type → Type u_1}
[Monad m]
{n : Nat}
:
BoundedRandom m (BitVec n)
Equations
def
Plausible.runRand
{m : Type → Type}
[Monad m]
[MonadLiftT (ST IO.RealWorld) m]
{α : Type}
(cmd : RandT m α)
:
m α
Computes a 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.