mathlib3 documentation

core / system.random

Basic random number generator support #

based on the one available on the Haskell library

@[class]
structure random_gen (g : Type u) :

Interface for random number generators.

Instances of this typeclass
Instances of other typeclasses for random_gen
  • random_gen.has_sizeof_inst
structure std_gen  :

"Standard" random number generator.

Instances for std_gen
def std_range  :
Equations
@[protected, instance]
Equations
Equations
Equations
@[protected, instance]
Equations
def mk_std_gen (s : := 0) :

Return a standard number generator.

Equations
def rand_nat {gen : Type u} [random_gen gen] (g : gen) (lo hi : ) :
× gen

Generate a random natural number in the interval [lo, hi].

Equations
  • rand_nat g lo hi = let lo' : := ite (lo > hi) hi lo, hi' : := ite (lo > hi) lo hi in rand_nat._match_2 g lo' hi' (random_gen.range g)
  • rand_nat._match_2 g lo' hi' (gen_lo, gen_hi) = let gen_mag : := gen_hi - gen_lo + 1, q : := 1000, k : := hi' - lo' + 1, tgt_mag : := k * q in rand_nat._match_1 lo' k (rand_nat_aux gen_lo gen_mag _ tgt_mag 0 g)
  • rand_nat._match_1 lo' k (v, g') = let v' : := lo' + v % k in (v', g')
def rand_bool {gen : Type u} [random_gen gen] (g : gen) :
bool × gen

Generate a random Boolean.

Equations