Alpha. Vary is under active development and not ready for production use. Syntax, APIs, performance, and behaviour may change between releases.
Random
The random module provides pseudorandom integer generation. For cryptographically secure randomness, use the crypto module instead.
from random import randint, seed
seed(42) # reproducible sequence
let roll = randint(1, 6) # random integer in [1, 6]
Functions
| Function | Returns | Description |
|---|---|---|
randint(a, b) | Int | Random int N where a <= N <= b (inclusive) |
randrange(start, stop) | Int | Random int N where start <= N < stop |
seed(n) | None | Set RNG seed for reproducible sequences |
from random import randint, randrange, seed
# Reproducible results
seed(123)
let a = randint(1, 100)
let b = randrange(0, 10) # 0..9
# Dice simulation
let die = randint(1, 6)
let coin = randint(0, 1) # 0 = tails, 1 = heads