1 # Generate random path-like strings, separated by null characters.
5 # awk -f ./generate.awk -v <variable>=<value> | tr '\0' '\n'
7 # Customizable variables (all default to 0):
8 # - seed: Deterministic random seed to use for generation
9 # - count: Number of paths to generate
10 # - extradotweight: Give extra weight to dots being generated
11 # - extraslashweight: Give extra weight to slashes being generated
12 # - extranullweight: Give extra weight to null being generated, making paths shorter
14 # Random seed, passed explicitly for reproducibility
17 # Don't include special characters below 32
19 # Don't include DEL at 128
21 upperascii = maxascii
- minascii
23 # add extra weight for ., in addition to the one weight from the ascii range
24 upperdot = upperascii
+ extradotweight
26 # add extra weight for /, in addition to the one weight from the ascii range
27 upperslash = upperdot
+ extraslashweight
29 # add extra weight for null, indicating the end of the string
30 # Must be at least 1 to have strings end at all
31 total = upperslash
+ 1 + extranullweight
33 # new=1 indicates that it's a new string
37 # Random integer between [0, total)
38 value = int
(rand
() * total
)
40 if (value
< upperascii
) {
42 printf("%c", value
+ minascii
)
45 } else if (value
< upperdot
) {
50 } else if (value
< upperslash
) {
51 # If it's the start of a new path, only generate a / in 10% of cases
52 # This is always an invalid subpath, which is not a very interesting case
53 if (new
&& rand
() > 0.1) continue
57 # Do not generate empty strings