import java.io.*; import java.math.*; import uk.ac.ed.ph.advcompsim.part3.histogram.Histogram; /** * --------------------------------------------------------------- * Excersize 3.1.3 * ---------------------------------------------------------------
* I would expect the histogram to be fairly flat, because over a large number of N I would expect the probability of getting a value in the region * 0-0.1 to be the same as that of getting a number in the region 0.4-0.5 for example. */ public class exc313 { /** * Takes a number n and prints that many random numbers. */ public static void main (String args[]) { int n = 200; // number of random numbers to be generated int nb = 10; // number of bins to use. float[] data = new float[n]; // The data array float lb = 0; // The lower boundary float ub = 1; // The upper boundary for(int i=0;i < n;i++) { data[i] = (float)(Math.random()); // print the randomly generated number to screen } //Histogram.DataHistogram(nb, lb, ub, data, true); } } THEN THE OTHER BITS 001 package uk.ac.ed.ph.advcompsim.part3.histogram; 002 003 import uk.ac.ed.ph.advcompsim.part3.display.GUI; 004 import java.awt.geom.Rectangle2D; 005 import uk.ac.ed.ph.advcompsim.part3.display.Board; 006 import uk.ac.ed.ph.advcompsim.part3.closure.Closure; 007 import java.awt.*; 008 import java.awt.Dimension; 009 import java.util.*; 010 011 /** 012 * This abstract base class provides basic methods and fields for the manipulation of 013 * histograms. It must be subclassed by a Histogram class, which defines methods 014 * for binning a data sample or a given function. 015 * 016 * 017 * @author M. L. Ciccolini 018 * @author Tony Kennedy 019 * @version 1.2 020 * @see Histogram Histogram 021 * @see Closure Closure 022 */ 023 024 public abstract class Histogram implements Closure { 025 026 /** Is the area normalized to one? */ 027 protected boolean normalized; 028 029 /** Number of bins */ 030 protected int numBins; 031 032 /** Width of the bins */ 033 protected float binWidth; 034 035 /** 036 * Cumulative area of the histogram in each bin, i.e., the area under the 037 * histogram up to and including that bin 038 */ 039 protected float[] area; 040 041 /** Total area under the (unnormalized) histogram */ 042 protected float totalArea; 043 044 /**Lower limit of the values included in the histogram */ 045 protected float lowerBound; 046 047 /** Upper limit of the values included in the histogram */ 048 protected float upperBound; 049 050 /** GUI in which to show graphs */ 051 private static GUI window = null; 052 053 /** 054 * Partially initialize an object belonging to a class derived from 055 * {@link Histogram}: