import java.util.Random; public class RandomExample { public static void main(String[] args) { Random rand = new Random(); double num = rand.nextGaussian(); System.out.println(num); } }
import java.util.Random; public class RandomExample { public static void main(String[] args) { Random rand = new Random(); double mean = 5.0; double stdDev = 2.0; double num = rand.nextGaussian() * stdDev + mean; System.out.println(num); } }This example generates a random number with a normal distribution, but with a mean of 5.0 and a standard deviation of 2.0. It then prints the number to the console. The package library used is java.util.Random.