Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Meera runs a simulation of 100 crosses twice and gets two different counts. Then she adds random.seed(4) at the top and gets the same count both times. Explain what changed, and whether the seed makes her result more accurate.
random.choice(parent) picks one gamete at random, and one choice from each parent makes a child. Counter(baby(...) for _ in range(n)) makes and counts n children. random.seed(k) repeats the same random numbers. A few plants wander far from the expected share; many plants settle near it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. Without a seed. The random numbers start from a new place each run, so the counts differ.
Step 2. With a seed. random.seed(4) starts them from the same place, so every run repeats the same count.
Step 3. Accuracy. The seed makes the result repeatable, not more accurate. A count of 100 plants still wanders; only more plants bring it closer to 25 %.
Answer: the seed makes the run repeat; it does not make it more accurate.
Log in to join the discussion.
Loading…