Mercurial > repo
annotate src/ploki/random.c @ 11559:467d5b4a5976 draft
<oerjan> revert
author | HackEso <hackeso@esolangs.org> |
---|---|
date | Tue, 15 May 2018 02:37:49 +0100 |
parents | ac0403686959 |
children |
rev | line source |
---|---|
4223 | 1 #include "config.h" |
2 #include "random.h" | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <time.h> | |
7 | |
8 void randseed(void) { | |
9 unsigned seed; | |
10 | |
11 seed = time(NULL); | |
12 #if HAVE_DEV_URANDOM_P | |
13 { | |
14 FILE *fp; | |
15 | |
16 if ((fp = fopen("/dev/urandom", "rb"))) { | |
17 fread(&seed, sizeof seed, 1, fp); | |
18 fclose(fp); | |
19 } | |
20 } | |
21 #endif | |
22 srand(seed); | |
23 } | |
24 | |
25 double randval(void) { | |
26 return rand() / (RAND_MAX + 1.0); | |
27 } |