Search⌘ K

Random Number Generation and Return Values

Learn about random number generation and return values in functions.

Random integers

We met the Math.random() method previously, which creates a random decimal between 000000 and 111111. We often need a random integer value in programs. In fact, we used the following code to choose a random number between 111111 and 101010101010 in the higher or lower game earlier:

Math.ceil(Math.random() * 10);

It’s a useful exercise to abstract this code into ...