Next

Random

A random number generator produces unpredictable numbers within a given range. Programs use randomness to simulate dice rolls, shuffle cards, generate computer moves, and anywhere else an outcome shouldn’t be predictable.

Creating a Generator#

Most languages require you to create a random number generator before using it.

Random random = new Random();

new Random() creates a generator seeded with the current time, which produces a different sequence of numbers each run.