In the Lotto game, part of the UK's National Lottery, seven distinct numbers are randomly chosen from the set {1, 2, ..., 49}, the seventh being called the Bonus Number. Write a program to simulate this. An example of your program's output could be:
Number 1: 43
Number 2: 28
Number 3: 33
Number 4: 18
Number 5: 11
Number 6: 30
Bonus Number: 6
To generate random numbers, you should create an instance of a Random
object:
Random generator = new Random();
Then, for a non-negative integer n, you can get a random integer between 0 and n by calling the nextInt
method, e.g.:
int x = generator.nextInt(n);
To use Random
you need to import it, by writing:
import java.util.Random;
at the top of your file.
The non-trivial aspect of this question is ensuring that the seven Lottery numbers chosen are all distinct.