From fa7ef572c782c9394f60202d950d3380dfdce5c3 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 29 Apr 2004 18:10:22 +0000 Subject: Implemented text and clipping primitives in the frontend, and added two new simple games `fifteen' and `sixteen'. [originally from svn r4173] --- misc.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 misc.c (limited to 'misc.c') diff --git a/misc.c b/misc.c new file mode 100644 index 0000000..58c4fb7 --- /dev/null +++ b/misc.c @@ -0,0 +1,25 @@ +/* + * misc.c: Miscellaneous helpful functions. + */ + +#include +#include + +#include "puzzles.h" + +int rand_upto(int limit) +{ + unsigned long divisor = RAND_MAX / (unsigned)limit; + unsigned long max = divisor * (unsigned)limit; + unsigned long n; + + assert(limit > 0); + + do { + n = rand(); + } while (n >= max); + + n /= divisor; + + return (int)n; +} -- cgit v1.1