Need a D20?
Random numbers are often needed in games. They are created by pseudo-random generators that create a sequence of apparently non-related numbers. In fact the next number depends on the last and one use a seed value to set the start number. The sequence will always be the same with the same seed. One common way to initialize the seed value is to use the current system time.
Number in a range
Its common for random functions (ex rand) to return a value between 0 and a very high positive number. To get a value inside a certain range use modulo operator and the initial value of the range.
rand() % 100 + 1; // To get a value between 1 to 100.
Generating random numbers from a specific distribution by inverting the cdf - 2017
Generating random numbers from a-specific distribution with rejection sampling - 2017
How chance in games is rarely just a roll of the dice - 2014
rand() Considered Harmful - 2013
rand() Considered Harmful - 2019