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
@[implicit_reducible]
instance
Plausible.instMonadLiftTRandGTOfMonadLift
{m : Type u_1 → Type u_2}
{n : Type u_1 → Type u_3}
{g : Type}
[MonadLift m n]
:
MonadLiftT (RandGT g m) (RandGT g n)
Equations
- Plausible.instMonadLiftTRandGTOfMonadLift = { monadLift := fun {α : Type ?u.32} (x : Plausible.RandGT g m α) (s : ULift g) => liftM (x s) }
@[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
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
Instances For
Create a new random number generator distinct from the one stored in the state
Equations
Instances For
def
Plausible.Random.randBound
{m : Type u → Type u_1}
{g : Type}
(α : Type u)
[LE α]
[BoundedRandom m α]
(lo hi : α)
(h : lo ≤ hi)
[RandomGen g]
:
Generate a random value of type α between x and y inclusive.
Equations
- Plausible.Random.randBound α lo hi h = Plausible.BoundedRandom.randomR lo hi h
Instances For
@[implicit_reducible]
Equations
- Plausible.Random.instBool = { random := fun {g : Type} [RandomGen g] => Plausible.Random.randBool }
@[implicit_reducible]
Equations
- One or more equations did not get rendered due to their size.
@[implicit_reducible]
Equations
- One or more equations did not get rendered due to their size.
@[implicit_reducible]
instance
Plausible.Random.instBoundedRandomFin
{m : Type → Type u_1}
[Monad m]
{n : Nat}
:
BoundedRandom m (Fin n)
Equations
- One or more equations did not get rendered due to their size.
@[implicit_reducible]
instance
Plausible.Random.instBoundedRandomBitVec
{m : Type → Type u_1}
[Monad m]
{n : Nat}
:
BoundedRandom m (BitVec n)
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- One or more equations did not get rendered due to their size.