public class MyRandom { public static void main(String[] args) { //Divide the interval [0, 1) into n subintervals. final int n = 20; int[] a = new int[n]; //n zeroes. //Could also say int a[] = new int[n]; for (int i = 0; i < 1000; ++i) { final double r = Math.random(); ++a[(int)(r * n)]; } for (int i = 0; i < a.length; ++i) { System.out.println(a[i]); } } }