diff options
author | Tharre <tharre3@gmail.com> | 2017-08-26 18:16:11 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2017-08-26 23:10:09 +0200 |
commit | 3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e (patch) | |
tree | f1a63e437e9d99c0cec9969ce9bc56eacb50cb7d /src/util.c | |
parent | 5d35df94d62b76cb55c14e70b079ceb2c400b326 (diff) | |
download | redo-3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e.tar.gz redo-3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e.tar.xz redo-3d81d35fa2225d434b14c5e6230a2b5b9bedfe6e.zip |
Use the proper RNG called PCG instead of rand()
Fixes #7.
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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; +} |