--seed is a command-line option for supplying an integer seed to Python's random module. Leaving it unset uses None, allowing ordinary pseudo-random behavior; supplying it makes random output repeatable for testing. section 9.3.1 section 10.3
A typical definition and use follow this pattern:
- Define the option with argparse, using type=int and default=None. section 12.0 section 19.1
- Pass the parsed value to random.seed(args.seed) before generating random output. section 10.3 section 10.1
- Let argparse reject non-integer values automatically. section 10.1
Repeatable random output
Run a randomizing program with a fixed seed, such as ./ransom.py --seed 3 'give us 2 million dollars or the cat gets it!'. Reusing seed 3 reproduces the same capitalization pattern, while omitting --seed leaves the output pseudo-random. section 12.0
$ ./telephone.py -h
usage: telephone.py [-h] [-s seed] [-m mutations] text
Telephone
positional arguments:
text Input text or file
optional arguments:
-h, --help show this help message and exit
-s seed, --seed seed Random seed (default: None)
-m mutations, --mutations mutations
Percent mutations (default: 0.1)
The usage listing shows the short and long forms, integer value, and None default alongside a runnable command-line interface. section 10.1
