diff options
Diffstat (limited to 'misc')
| -rw-r--r-- | misc/subr.c | 7 | ||||
| -rw-r--r-- | misc/subr.h | 2 |
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 |