Lean4
/-- Execute `RandT m α` 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.
-/
def runRand (cmd : RandT m α) : m α := do
let stdGen ← ULiftable.up (stdGenRef.get : m₀ _)
let (res, new) ← StateT.run cmd stdGen
let _ ← ULiftable.up (stdGenRef.set new.down : m₀ _)
pure res