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 #
RandandRandGmonad for computations guided by randomness;Randomclass 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 theIOmonad;
References #
- Similar library in Haskell: https://hackage.haskell.org/package/MonadRandom
Create a new random number generator distinct from the one stored in the state
Equations
- Rand.split = do let __do_lift ← get let rng : g := __do_lift.down match RandomGen.split rng with | (r1, r2) => do set { down := r1 } pure r2
Instances For
def
Random.randBound
{g : Type}
(α : Type u)
[Preorder α]
[BoundedRandom α]
(lo : α)
(hi : α)
(h : lo ≤ hi)
[RandomGen g]
:
Generate a random value of type α between x and y inclusive.
Equations
- Random.randBound α lo hi h = BoundedRandom.randomR lo hi h
Instances For
Equations
- Random.instRandomBool = { random := fun {g} [RandomGen g] => Random.randBool }
Equations
- Random.instRandomULift = { random := fun {g} [RandomGen g] => ULiftable.up Random.random }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
instance
Random.instBoundedRandomULiftInstPreorderULift
{α : Type u}
[Preorder α]
[BoundedRandom α]
:
Equations
- One or more equations did not get rendered due to their size.
Computes a Rand α 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.
Instances For
Equations
- IO.runRandWith seed cmd = pure (StateT.run cmd { down := mkStdGen seed }).fst