Documentation

HexBasic.Rand

structure Hex.Rand :

A splitmix64 state. Deterministic, seedable, and reproducible across runs and platforms; this is a source of arbitrary values for Las Vegas search, not a cryptographic generator, and nothing in the tree may treat it as one.

  • state : UInt64

    The 64-bit generator state.

Instances For
    @[instance_reducible]
    Equations
    def Hex.instDecidableEqRand.decEq (x✝ x✝¹ : Rand) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For

      Advance the splitmix64 state and produce one 64-bit output.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        inductive Hex.RandError :

        Why a bounded draw failed.

        • zeroBound : RandError

          The requested bound was 0, so no value below it exists.

        • exhausted (attempts : Nat) (rand : Rand) : RandError

          Rejection sampling ran out of fuel; the attempt count and the advanced state are returned so the caller can resume rather than replay a failed stream.

        Instances For
          Equations
          Instances For
            def Hex.Rand.words (r : Rand) :

            Concatenate w fresh 64-bit words into one natural number below 2 ^ (64 * w).

            Equations
            Instances For
              def Hex.Rand.nat (r : Rand) (bound fuel : Nat) :

              Draw a natural number below bound by rejection sampling: form a candidate from enough 64-bit words and reject the incomplete top interval (rather than folding it in with next % bound, which would add modulo bias). fuel bounds the rejection retries, including the initial candidate; bound = 0 returns zeroBound.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Hex.Rand.ofSeed (seed : Nat) :

                Construct the initial state from a seed.

                Equations
                Instances For
                  theorem Hex.Rand.nat_lt {r : Rand} {bound fuel v : Nat} {r' : Rand} (h : r.nat bound fuel = Except.ok (v, r')) :
                  v < bound

                  Range correctness: a successful bounded draw is below the bound.