aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c12
1 files changed, 12 insertions, 0 deletions
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;
+}