OpenCyber Academy
Rapid course · Lesson 6 · English
Course code: OCA-020Lesson 06: OCA-020-A006

Five seeds are not one rate

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Lesson map

Lesson 06. Map, example, EX052.

flowchart TD
  S["Seeds 0, 1, 2, 3 and 4"] --> B["200 draws each, threshold 0.12"]
  B --> R["Five printed rates"]
  R --> M["Mean 0.125 and sample sd 0.017"]

The 0.12 inside the source is a draw threshold. It is not one of the five printed rates.

Logical drawing

per-seed rates: 0.110 0.130 0.135 0.105 0.145 mean=0.125 sd=0.017

Learning outcomes

After this chapter, you should be able to:

  1. List the five printed rates in seed order.
  2. Say why the mean is 0.125 when the source threshold is 0.12.
  3. Name the divisor 4 in the standard-deviation line.

6.1 Each seed builds its own generator and its own 200 draws.

The loop is for seed in range(5). Seed 0 runs first. Seed 4 runs last. Each pass constructs random.Random(seed) and counts how often r.random() < 0.12 across 200 draws. That count divided by 200 is one rate. The five rates print as 0.110 0.130 0.135 0.105 0.145.

The mean is the sum of those five rates divided by 5, which is 0.125. The standard deviation takes the squared gaps from that mean, divides by 4, and then takes the square root. The divisor is len(rates) - 1, the sample divisor, not 5. The printed sd is 0.017.

The threshold 0.12 never appears in the output line. A note that replaces the five rates with 0.12 has substituted the generator's cutoff for the realised counts. Those counts differ because each seed starts a different stream.

Lesson table; scroll horizontally to read all columns →

Piece Role in this print
Seeds 0 through 4 Order of the five rates
200 draws Denominator of each rate
Threshold 0.12 Not printed
Divide by 4 Sample sd, printed 0.017

6.2 Worked example

Lesson table; scroll horizontally to read all columns →

Claim Decision
The five numbers are 0.110, 0.130, 0.135, 0.105, 0.145 Keep
Their mean is the threshold 0.12 Refuse; the mean prints 0.125
One unlucky seed can sit at 0.105 Keep; that is seed 3's rate
The sd divided by 5 Refuse; the code divides by 4

Synthetic case. These seeds score a toy defence. They are not staff mailboxes.

Errors and limits

Collapsing five seeds into the source threshold erases the spread the line was printed to show.

Apply

  • EX052 — Five seeds. What does the per-seed line report, and why is 0.12 absent from it?
    Show marking criteria
    Rubric: 3 = the five rates, mean 0.125, sample sd 0.017 using divisor 4; 0.12 is only the draw threshold;; 2 = the five rates and the mean;; 1 = the mean only;; 0 = treats 0.12 as a printed rate.
Worked answers

EX052. Seeds 0 through 4 each take 200 draws against the threshold 0.12. The printed rates are 0.110, 0.130, 0.135, 0.105 and 0.145. Their mean is 0.125. The standard deviation divides by 4 and prints 0.017. The threshold 0.12 is not a printed rate.