public class SampleGaussian {

    public static double [] getHistogram (
            double mu, double sigma,
            int trials, int nbins,
            double xmin, double xmax) {

        // Create histogram to bin x-values sampled from Gaussian.
        // Note: using double components rather than int, so that
        // final histogram can be normalized...
        double [] histogram = new double [nbins];

        double dx = (xmax - xmin) / nbins;      // Find x-span of each bin

        for (int t = 0; t < trials; t++) {
            double z = 0;           // This is where you come in...

            // Each time through this loop, assign a random value to z
            // using each of two methods (one at a time, of course):
            //
            // 1) the Box-Muller formula for sampling from a standard
            //    Gaussian (see Exercise 1.2.27 in your text)
            //
            // 2) the inverse-Phi method (get help from your instructor
            //    for this one)





            
            double x = sigma * z + mu;          // Allow for any mu, sigma
            int ix = (int) ((x - xmin) / dx);   // Find the right bin
            if (ix >= 0 && ix < nbins)          // If index in range,
                histogram [ix]++;               // add 1 to appropriate bin
        }

        for (int i = 0; i < nbins; i++) {
            histogram[i] /= (trials * dx);
        }

        return histogram;
    }
}
