/* makes a star object located uniformly at random within the limits given on the sphere */ void make_rand_star(double* star, double ramin, double ramax, double decmin, double decmax) { double decval, raval; if (ramin < 0.0) ramin = 0.0; if (ramax > (2*M_PI)) ramax = 2 * M_PI; if (decmin < -M_PI / 2.0) decmin = -M_PI / 2.0; if (decmax > M_PI / 2.0) decmax = M_PI / 2.0; decval = asin(uniform_sample(sin(decmin), sin(decmax))); raval = uniform_sample(ramin, ramax); star[0] = radec2x(raval, decval); star[1] = radec2y(raval, decval); star[2] = radec2z(raval, decval); }
static double gaussian_sample(double mean, double stddev) { // from http://www.taygeta.com/random/gaussian.html // Algorithm by Dr. Everett (Skip) Carter, Jr. static double y2 = GAUSSIAN_SAMPLE_INVALID; double x1, x2, w, y1; // this algorithm generates random samples in pairs; the INVALID // jibba-jabba stores the second value until the next time the // function is called. if (y2 != GAUSSIAN_SAMPLE_INVALID) { y1 = y2; y2 = GAUSSIAN_SAMPLE_INVALID; return mean + y1 * stddev; } do { x1 = uniform_sample(-1, 1); x2 = uniform_sample(-1, 1); w = x1 * x1 + x2 * x2; } while ( w >= 1.0 ); w = sqrt( (-2.0 * log(w)) / w ); y1 = x1 * w; y2 = x2 * w; return mean + y1 * stddev; }