summaryrefslogtreecommitdiff
path: root/src/rand.c
blob: 1a6a3d439b4ff97e12f96f82c32061dc56f0aa19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}