From 03de79b8c5ebcc206e3450dfbc701211d9c254b0 Mon Sep 17 00:00:00 2001 From: pants Date: Fri, 9 Sep 2016 14:33:56 -0400 Subject: more refactoring --- src/rand.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/rand.c (limited to 'src/rand.c') diff --git a/src/rand.c b/src/rand.c new file mode 100644 index 0000000..1a6a3d4 --- /dev/null +++ b/src/rand.c @@ -0,0 +1,20 @@ + +#include "fracture.h" + +unsigned long int rand_seed() { + FILE *f = fopen("/dev/urandom", "r"); + unsigned long int seed; + fread(&seed, sizeof(unsigned long int), 1, f); + fclose(f); + return seed; +} + +double rand_dist_pow(const gsl_rng *r, double beta) { + double x = 0; + + // underflow means that for very small beta x is sometimes identically zero, + // which causes problems + while ((x = exp(log(gsl_rng_uniform_pos(r)) / beta)) == 0.0); + + return x; +} -- cgit v1.2.3-70-g09d2