liveBook · Manning

--seed

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

A book-specific command-line option that specifies the seed controlling pseudo-random password generation.

--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:

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

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Explains argparse typing, the None default, and random.seed() placement, but defers random-number internals.
Examples
Demonstrates reproducible ransom capitalization, telephone mutation setup, scrambled words, workouts, and generated passwords.
What it assumes
Assumes familiarity with Python functions and command-line arguments while demonstrating argparse integer conversion from the option definition.
What you can do after
Operate Python randomizing programs reproducibly by defining an integer option and passing its value to random.seed().
How it connects
Connects command-line arguments with argparse, random.seed(), pseudo-randomness, and automated testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.