Cookbook
Randomness

Randomness

This page lists examples of working with random numbers, uncertainty and randomness in general.

How to generate a random number

// Declare a variable to store the random number
let number: Int;
 
// Generate a new random number, which is an unsigned 256-bit integer
number = randomInt();
 
// Generate a random number between 1 and 12
number = random(1, 12);
🤔

Didn't find your favorite example of working with randomness? Have cool implementations in mind? Contributions are welcome! (opens in a new tab)