From 3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e Mon Sep 17 00:00:00 2001 From: Tharre Date: Sat, 26 Aug 2017 18:16:11 +0200 Subject: Use the proper RNG called PCG instead of rand() Fixes #7. --- src/util.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 35db2e3..266cf90 100644 --- a/src/util.c +++ b/src/util.c @@ -121,3 +121,15 @@ void hex_to_sha1(const char *s, unsigned char *sha1) { *sha1 = ((strchr(hex, *s) - hex) << 4) + strchr(hex, *(s+1)) - hex; } +uint32_t generate_seed() { + uint32_t seed; + FILE *fp = fopen("/dev/urandom", "rb"); + if (!fp) + fatal("redo: failed to open /dev/urandom"); + + if (fread(&seed, 1, 4, fp) < 4) + fatal("redo: failed to read from /dev/urandom"); + + fclose(fp); + return seed; +} -- cgit v1.2.3-70-g09d2