ref: e6aa7ab6dd219d92b332c3662de95c28f7bd6b8f
parent: 73dab39bf5661565f97b2a9571547d5c62f13e39
author: Simon Tatham <[email protected]>
date: Thu Mar 30 04:45:06 EDT 2023
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!
--- a/hat.c
+++ b/hat.c
@@ -1423,7 +1423,8 @@
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 @@
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 @@
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;