9.9. 乱数(Random Numbers)

🔗def
IO.setRandSeed (n : Nat) : BaseIO Unit
🔗def
IO.rand (lo hi : Nat) : BaseIO Nat
🔗def
randBool.{u} {gen : Type u} [RandomGen gen]
    (g : gen) : Bool × gen

Generate a random Boolean.

🔗def
randNat.{u} {gen : Type u} [RandomGen gen]
    (g : gen) (lo hi : Nat) : Nat × gen

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

9.9.1. 乱数生成(Random Generators)

🔗type class
RandomGen.{u} (g : Type u) : Type u

Interface for random number generators.

Instance Constructor

RandomGen.mk.{u}

Methods

range : gNat × Nat

range returns the range of values returned by the generator.

next : gNat × g

next operation returns a natural number that is uniformly distributed the range returned by range (including both end points), and a new generator.

split : gg × g

The 'split' operation allows one to obtain two distinct random number generators. This is very useful in functional programs (for example, when passing a random number generator down to recursive calls).

🔗structure
StdGen : Type

"Standard" random number generator.

Constructor

StdGen.mk

Fields

s1 : Nat
s2 : Nat
🔗def
stdRange : Nat × Nat
🔗def
stdNext : StdGenNat × StdGen
🔗def
stdSplit : StdGenStdGen × StdGen
🔗def
mkStdGen (s : Nat := 0) : StdGen

Return a standard number generator.

9.9.2. システムの乱数(System Randomness)

🔗opaque
IO.getRandomBytes (nBytes : USize)
    : IO ByteArray

Read bytes from a system entropy source. Not guaranteed to be cryptographically secure. If nBytes = 0, return immediately with an empty buffer.