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 /cube.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 'cube.c')
| -rw-r--r-- | cube.c | 26 |
1 files changed, 3 insertions, 23 deletions
@@ -511,15 +511,7 @@ char *new_game_seed(game_params *params) for (i = 0; i < data.nclasses; i++) { for (j = 0; j < facesperclass; j++) { - unsigned long divisor = RAND_MAX / data.nsquares[i]; - unsigned long max = divisor * data.nsquares[i]; - unsigned long n; - - do { - n = rand(); - } while (n >= max); - - n /= divisor; + int n = rand_upto(data.nsquares[i]); assert(!flags[data.gridptrs[i][n]]); flags[data.gridptrs[i][n]] = TRUE; @@ -529,7 +521,7 @@ char *new_game_seed(game_params *params) * better data structure for this, but for such small * numbers it hardly seems worth the effort. */ - while ((int)n < data.nsquares[i]-1) { + while (n < data.nsquares[i]-1) { data.gridptrs[i][n] = data.gridptrs[i][n+1]; n++; } @@ -567,19 +559,7 @@ char *new_game_seed(game_params *params) /* * Choose a non-blue square for the polyhedron. */ - { - unsigned long divisor = RAND_MAX / m; - unsigned long max = divisor * m; - unsigned long n; - - do { - n = rand(); - } while (n >= max); - - n /= divisor; - - sprintf(p, ":%d", data.gridptrs[0][n]); - } + sprintf(p, ":%d", rand_upto(m)); sfree(data.gridptrs[0]); sfree(flags); |