From bf6b7fbdab8e3d3f025954fdb559310c452271e0 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Mon, 18 Nov 2019 11:22:24 -0600 Subject: add a new test for the quad fitter This commit adds a new test to test the quad fitter when the t0 quantile argument is less than 1. --- src/random.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/random.c') diff --git a/src/random.c b/src/random.c index 482e102..8f005eb 100644 --- a/src/random.c +++ b/src/random.c @@ -18,13 +18,14 @@ #include #include #include +#include "vector.h" static gsl_rng *r; +/* Generates a random number from a normal distribution using the Box-Muller + * transform. */ double randn(void) { - /* Generates a random number from a normal distribution using the - * Box-Muller transform. */ double u1, u2; u1 = genrand_real1(); @@ -33,9 +34,23 @@ double randn(void) return sqrt(-2*log(u1))*cos(2*M_PI*u2); } +/* Generates a random point in the unit sphere. */ +void rand_ball(double *pos, double radius) +{ + pos[0] = (genrand_real2()*2 - 1)*radius; + pos[1] = (genrand_real2()*2 - 1)*radius; + pos[2] = (genrand_real2()*2 - 1)*radius; + + while (NORM(pos) >= radius) { + pos[0] = (genrand_real2()*2 - 1)*radius; + pos[1] = (genrand_real2()*2 - 1)*radius; + pos[2] = (genrand_real2()*2 - 1)*radius; + } +} + +/* Generates a random point on the unit sphere. */ void rand_sphere(double *dir) { - /* Generates a random point on the unit sphere. */ double u, v, theta, phi; u = genrand_real1(); -- cgit