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
@[reducible, inline]
A monad to generate random objects using the generator type StdGen.
Instances For
@[implicit_reducible]
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
Create a new random number generator distinct from the one stored in the state.
Instances For
Get the range of Nat that can be generated by the generator g.
Instances For
def
Random.randBound
{m : Type u → Type u_1}
{g : Type}
(α : Type u)
[Preorder α]
[BoundedRandom m α]
(lo hi : α)
(h : lo ≤ hi)
[RandomGen g]
:
Generate a random value of type α between x and y inclusive.
Instances For
def
Random.randFin
{m : Type → Type u_1}
[Monad m]
{g : Type}
{n : â„•}
[NeZero n]
[RandomGen g]
:
RandGT g m (Fin n)
Generate a random Fin.
Instances For
@[implicit_reducible]
instance
Random.instFinOfNeZeroNat
{m : Type → Type u_1}
[Monad m]
{n : â„•}
[NeZero n]
:
Random m (Fin n)
Generate a random Bool.
Instances For
@[implicit_reducible]
@[implicit_reducible]
@[implicit_reducible]
@[implicit_reducible]
instance
Random.instBoundedRandomFin
{m : Type → Type u_1}
[Monad m]
{n : â„•}
:
BoundedRandom m (Fin n)
@[implicit_reducible]
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} α)
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.