import java.util.*; import java.awt.*; // A class to hold an (x,y) pair where both are double's. class Pointd { double x, y; } public class Histogram2D { public static void main (String[] argv) { // Number of points to generate. int numSamples = 1000; Pointd[] points = new Pointd [1000]; // Generate random points from a Gaussian distribution // where both x and y are in the range [0,4]. for (int n=0; n= 2) ) { x = rand.nextGaussian (); } p.x = x + 2; // Generate y value. double y = rand.nextGaussian (); while ( (y <= -2) || (y >= 2) ) { y = rand.nextGaussian (); } p.y = y + 2; return p; } static Pointd nextUniform () { Pointd p = new Pointd (); // Random.nextDouble() generates between 0 and 1. We will // scale by 4 to create a point in the interval [0,4]. p.x = 4 * rand.nextDouble (); p.y = 4 * rand.nextDouble (); return p; } static Integer[][] makeHistogram (Pointd[] points) { // Size of histogram. int size = 10; // Make the space for it, using instances of java.lang.Integer. Integer[][] hist = new Integer [size][size]; // Initialize: must create an instance. for (int i=0; i