about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2005-12-14 17:31:16 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2005-12-14 17:31:16 +0000
commitb2bf61dbf7b1c83d867f672cd5dad503e92c6362 (patch)
treebbdc58438a41144817b8274d16cb25416927bce3 /misc
parentc347106fc1aadcee0a13d54a413e65880ac9df2f (diff)
downloadbtpd-b2bf61dbf7b1c83d867f672cd5dad503e92c6362.tar.gz
btpd-b2bf61dbf7b1c83d867f672cd5dad503e92c6362.zip
Add and use rand_between.
Diffstat (limited to 'misc')
-rw-r--r--misc/subr.c7
-rw-r--r--misc/subr.h2
2 files changed, 9 insertions, 0 deletions
diff --git a/misc/subr.c b/misc/subr.c
index f894812..77e3a06 100644
--- a/misc/subr.c
+++ b/misc/subr.c
@@ -5,6 +5,7 @@
 #include <fcntl.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <math.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -139,3 +140,9 @@ round_to_page(size_t size)
         size += psize - rem;
     return size;
 }
+
+long
+rand_between(long min, long max)
+{
+    return min + (long)rint((double)random() * (max - min) / RAND_MAX);
+}
diff --git a/misc/subr.h b/misc/subr.h
index 9467839..62c92c4 100644
--- a/misc/subr.h
+++ b/misc/subr.h
@@ -18,4 +18,6 @@ int canon_path(const char *path, char **res);
 
 size_t round_to_page(size_t size);
 
+long rand_between(long min, long max);
+
 #endif