aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2023-03-30 08:45:06 +0100
committerSimon Tatham <anakin@pobox.com>2023-03-30 08:45:06 +0100
commite6aa7ab6dd219d92b332c3662de95c28f7bd6b8f (patch)
tree69cecdffd0e75124e6aa1b893fd7e9e3e30b14b1
parent73dab39bf5661565f97b2a9571547d5c62f13e39 (diff)
downloadpuzzles-e6aa7ab6dd219d92b332c3662de95c28f7bd6b8f.zip
puzzles-e6aa7ab6dd219d92b332c3662de95c28f7bd6b8f.tar.gz
puzzles-e6aa7ab6dd219d92b332c3662de95c28f7bd6b8f.tar.bz2
puzzles-e6aa7ab6dd219d92b332c3662de95c28f7bd6b8f.tar.xz
hat-test: allow choosing a random number seed.
The default one is always the same, because the main purpose of this tool is debugging. But one person has already wanted to use it for actually generating a tiling patch for another use, so let's make it easier to vary the randomness!
-rw-r--r--hat.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/hat.c b/hat.c
index a269ae7..533855d 100644
--- a/hat.c
+++ b/hat.c
@@ -1423,7 +1423,8 @@ int main(int argc, char **argv)
KiteEnum s[1];
HatCoordContext ctx[1];
HatCoords *coords[KE_NKEEP];
- random_state *rs = random_new("12345", 5);
+ random_state *rs;
+ const char *random_seed = "12345";
int w = 10, h = 10;
int argpos = 0;
size_t i;
@@ -1434,13 +1435,17 @@ int main(int argc, char **argv)
while (--argc > 0) {
const char *arg = *++argv;
if (!strcmp(arg, "--help")) {
- printf("usage: hat-test [<width>] [<height>]\n"
- " or: hat-test --test\n");
+ printf(" usage: hat-test [options] [<width>] [<height>]\n"
+ "options: --python write a Python function call per hat\n"
+ " --seed=STR vary the starting random seed\n"
+ " also: hat-test --test\n");
return 0;
} else if (!strcmp(arg, "--test")) {
return unit_tests() ? 0 : 1;
} else if (!strcmp(arg, "--python")) {
dctx->outfmt = OF_PYTHON;
+ } else if (!strncmp(arg, "--seed=", 7)) {
+ random_seed = arg+7;
} else if (arg[0] == '-') {
fprintf(stderr, "unrecognised option '%s'\n", arg);
return 1;
@@ -1462,6 +1467,7 @@ int main(int argc, char **argv)
for (i = 0; i < lenof(coords); i++)
coords[i] = NULL;
+ rs = random_new(random_seed, strlen(random_seed));
init_coords_random(ctx, rs);
bbox->started = false;