diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-02-02 18:33:22 -0500 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-02-02 18:33:22 -0500 |
commit | 2af9351db3aa97da9b0d3f23d53a593bc96c8a8e (patch) | |
tree | 684dfccba8d295c42ef6e2e070c8d6caca45f590 /lib/rand.c | |
parent | 181db84a8ffb26e436a43bb268fe5ef060206e66 (diff) | |
download | c++-2af9351db3aa97da9b0d3f23d53a593bc96c8a8e.tar.gz c++-2af9351db3aa97da9b0d3f23d53a593bc96c8a8e.tar.bz2 c++-2af9351db3aa97da9b0d3f23d53a593bc96c8a8e.zip |
does potts now, no external libraries
Diffstat (limited to 'lib/rand.c')
-rw-r--r-- | lib/rand.c | 20 |
1 files changed, 20 insertions, 0 deletions
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 <assert.h> +#include <stdio.h> + +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; +} |