Skip to content

random

Built-in function · Available everywhere, with no import

random picks a whole number from a Range, with every number in it equally likely: a dice roll, a card position, a random guess.

const roll = random(1..6)
print("You rolled #{roll}")

random(range: Range): Int

One number from range. The range’s ends decide what is possible: random(1..6) can give 6, but random(0..<10) can never give 10.

Raises when range is empty.

A list picks one of its own items with random() and shuffles with shuffle(). For the same random numbers on every run, as a test or a replayable game needs, use a Random made with a seed.