From e6aa7ab6dd219d92b332c3662de95c28f7bd6b8f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 30 Mar 2023 08:45:06 +0100 Subject: [PATCH] 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! --- hat.c | 12 +++++++++--- 1 file 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 [] []\n" - " or: hat-test --test\n"); + printf(" usage: hat-test [options] [] []\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;