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 #
Rand
andRandG
monad for computations guided by randomness;Random
class for objects that can be generated randomly;random
to generate one object;
BoundedRandom
class for objects that can be generated randomly inside a range;randomR
to generate one object inside a range;
IO.runRand
to run a randomized computation inside theIO
monad;
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:
stdGenRef
is not necessarily properly seeded on program startup as of now and will therefore be deterministic.stdGenRef
is 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