import java.security.SecureRandom;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.random.RandomGenerator;

/**
 * The four ways to get a random number in Java, side by side.
 * Run with: java QuickStart.java   (JDK 17 or newer)
 */
public class QuickStart {
    public static void main(String[] args) {
        // 1. java.util.Random: fine for games and tests, repeatable when seeded. Never for secrets.
        Random random = new Random(42);
        System.out.println("Random(42)          : " + random.nextInt(1, 7));

        // 2. ThreadLocalRandom: the fast choice when many threads need numbers. Cannot be seeded.
        System.out.println("ThreadLocalRandom   : " + ThreadLocalRandom.current().nextInt(1, 7));

        // 3. SecureRandom: unpredictable. Use it for tokens, passwords, keys, anything an attacker would want to guess.
        System.out.println("SecureRandom        : " + new SecureRandom().nextInt(1, 7));

        // 4. RandomGenerator: the interface behind all of the above, plus a catalogue of modern algorithms.
        RandomGenerator generator = RandomGenerator.getDefault();
        System.out.println("RandomGenerator     : " + generator.nextInt(1, 7));
    }
}
