Further programming language operations - AQARandom number generation

Proficient programming requires knowledge of many techniques. These techniques allow for powerful, complex programs.

Part ofComputer ScienceComputational thinking and problem solving

Random number generation

Sometimes a programmer needs the to generate a number or letter within a specific range. This requires the program to create a random number. Programming games that involve chance, such as dice, require random numbers as do many types of program that need to be unpredictable.

Wheel with numbers in a random order
dice ← RANDOM_INT(1,6)
OUTPUT “you rolled a ” + INT_TO_STRING(dice) + “!”

Random numbers are not just used for rolling dice and games of chance. When sending across a , a wireless waits for a random amount of time before transmitting the data to avoid collisions. Random numbers are often used to generate secure passwords that are difficult to crack.