~/bend-docscommunity

rng.bend checks

raw source on the hub · import 0xd1de66b5d9157913a654c39186289f3d/rng.bend as Rng

RandomProvider surface — C# Unsga3.Utilities.RandomProvider. Seed + NextDouble in [0, 1) + Next / NextExcept for tournament. Portable Numerical Recipes LCG (not .NET System.Random). Algorithm A/B fronts will not match C# bit-for-bit because of this RNG delta.

Affine API: next_double / next_nat return the advanced state; last_double / last_nat are that draw. Callers use lets, not pair-destructure.

1 import
import Base

Types

type State source · line 12 · raw

Data

Definitions

def new source · line 20 · raw

@+s0:U32 -> State

def from_nat source · line 23 · raw

@seed:Nat -> State

def seed_of source · line 26 · raw

@s:State -> U32

def last_double source · line 31 · raw

@s:State -> F32

def last_nat source · line 36 · raw

@s:State -> Nat

def step source · line 41 · raw

@u:U32 -> U32

def to_unit source · line 45 · raw

@u:U32 -> F32

Top 24 bits / 2^24 so the F32 mantissa is exact and the value is in [0, 1).

def next_double source · line 48 · raw

@s:State -> State

def pred_or_zero source · line 54 · raw

@n:Nat -> Nat

def clamp_lt.fin source · line 61 · raw

@+i:Nat -> @+n:Nat -> @ok:Bool -> Nat

def clamp_lt source · line 68 · raw

@+i:Nat -> @+n:Nat -> Nat

def idx_from source · line 71 · raw

@+z:F32 -> @n:Nat -> Nat

def with_k source · line 78 · raw

@s:State -> @k2:Nat -> State

def next_nat source · line 84 · raw

@s:State -> @n:Nat -> State

Uniform integer in [0, n). n == 0n → 0n.

def bump_except source · line 88 · raw

@+v:Nat -> @+exclude:Nat -> @below:Bool -> Nat

def next_except.go source · line 96 · raw

@s:State -> @+exclude:Nat -> @n:Nat -> State

C# NextExcept: uniform in [0, n) distinct from exclude when n > 1.

def next_except source · line 107 · raw

@s:State -> @n:Nat -> @exclude:Nat -> State