aboutsummaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-04-29 18:10:22 +0000
committerSimon Tatham <anakin@pobox.com>2004-04-29 18:10:22 +0000
commitfa7ef572c782c9394f60202d950d3380dfdce5c3 (patch)
tree984a03da8e557cf27c7777461aa444a3142da117 /misc.c
parent4b9d75525238972f1ca30e37034c57c523a3fda1 (diff)
downloadpuzzles-fa7ef572c782c9394f60202d950d3380dfdce5c3.zip
puzzles-fa7ef572c782c9394f60202d950d3380dfdce5c3.tar.gz
puzzles-fa7ef572c782c9394f60202d950d3380dfdce5c3.tar.bz2
puzzles-fa7ef572c782c9394f60202d950d3380dfdce5c3.tar.xz
Implemented text and clipping primitives in the frontend, and added
two new simple games `fifteen' and `sixteen'. [originally from svn r4173]
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c25
1 files changed, 25 insertions, 0 deletions
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 <assert.h>
+#include <stdlib.h>
+
+#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;
+}