From 2af9351db3aa97da9b0d3f23d53a593bc96c8a8e Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 2 Feb 2018 18:33:22 -0500 Subject: does potts now, no external libraries --- lib/rand.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/rand.c (limited to 'lib/rand.c') diff --git a/lib/rand.c b/lib/rand.c new file mode 100644 index 0000000..76f537d --- /dev/null +++ b/lib/rand.c @@ -0,0 +1,20 @@ + +#include +#include + +unsigned long int rand_seed() { + /* + returns a random unsigned long integer read from the standard unix + pseudorandom device /dev/urandom + */ + + FILE *f = fopen("/dev/urandom", "r"); + assert(f != NULL); + + unsigned long int seed; + fread(&seed, sizeof(unsigned long int), 1, f); + + fclose(f); + + return seed; +} -- cgit v1.2.3-70-g09d2