From b2bf61dbf7b1c83d867f672cd5dad503e92c6362 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Wed, 14 Dec 2005 17:31:16 +0000 Subject: Add and use rand_between. --- misc/subr.c | 7 +++++++ misc/subr.h | 2 ++ 2 files changed, 9 insertions(+) (limited to 'misc') 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 #include #include +#include #include #include #include @@ -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 -- cgit 1.4.1