summaryrefslogtreecommitdiff
path: root/src/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rand.c')
-rw-r--r--src/rand.c20
1 files changed, 20 insertions, 0 deletions
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;
+}