random

Random numbers, picks and shuffles (use seed(n) to repeat them).

import random

Example

import random

random.seed(7)
say(random.int(1, 6))
say(random.choice(["tea", "coffee", "cocoa"]))
say(random.shuffle([1, 2, 3, 4, 5]))

Functions

int(low, high)

returns number

A random whole number from low to high (both included).

number()

returns number

A random number from 0 up to (not including) 1.

choice(list)

returns value

One item picked at random.

shuffle(list)

returns list

A new list with the same items in a random order.

sample(list, n)

returns list

n different items picked at random.

seed(n)

Start the random numbers from n, so the program picks the same ones every run.