Module std/random.vv
The random module provides functions for generating random numbers and making random choices.
Example:
import random from "std/random.vv"
random.seed(42)
let n = random.int(1, 100)
let x = random.choice(["a", "b", "c"])
Exports
fun seed(n)
extern "native"
Seeds the random number generator with the given integer.
Example:
random.seed(42)
fun float()
extern "native"
Returns a random floating-point number in the range [0.0, 1.0).
Example:
let f = random.float()
fun int(min, max)
extern "native"
Returns a random integer in the range [min, max) (exclusive).
Example:
let n = random.int(1, 10) // Returns 1-9
fun choice(xs)
Returns a random element from the given list.
Example:
let x = random.choice([1, 2, 3])