Generate random numbers using Random class

The Random class allows instantiating a random number generator with or without manually setting an internal random variable (seed parameter). If the seed parameter is passed, the random number generator initializes its internal counter with this value. On the other hand, if the parameterless constructor is called, it initializes the random number generator based on the current system time.

import java.util.Random;

public class RandomNumbersExample {
    public static void main(String[] args) {
        Random rand = new Random();
        int upperLimit = 10;

        int randomInteger = rand.nextInt(upperLimit);
        float randomFloat = rand.nextFloat();
        double randomDouble = rand.nextDouble();

        System.out.println("random integer: " + randomInteger + "\nrandom float: " + randomFloat + "\nrandom double: "
                + randomDouble);
        System.out.println("random numbers:");

        for (int counter = 1; counter <= 10; counter++) {
            System.out.print(rand.nextInt(50) + " ");
        }
    }
}
Output first run
random integer: 3
random float: 0.2686128
random double: 0.20795575941751465
random numbers:
41 38 31 36 40 34 47 29 33 26
Output second run
random integer: 6
random float: 0.71186566
random double: 0.8480369669637289
random numbers:
5 47 37 40 17 22 13 37 8 13