diff options
| author | Simon Tatham <anakin@pobox.com> | 2004-04-29 18:10:22 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2004-04-29 18:10:22 +0000 |
| commit | fa7ef572c782c9394f60202d950d3380dfdce5c3 (patch) | |
| tree | 984a03da8e557cf27c7777461aa444a3142da117 /misc.c | |
| parent | 4b9d75525238972f1ca30e37034c57c523a3fda1 (diff) | |
| download | puzzles-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.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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; +} |