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

FunctionReturnsDescription
randint(a, b)IntRandom int N where a <= N <= b (inclusive)
randrange(start, stop)IntRandom int N where start <= N < stop
seed(n)NoneSet 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