Quantum computing basics · Lesson 3 of 3
Quantum computing basics · Lesson 3 of 3
Measuring a qubit gives a single 0 or 1, and the superposition is gone. To learn the probabilities, a quantum computer runs the same program many times; each run is called a shot, and the results are counted.
We can simulate this with random numbers: draw a number between 0 and 1; if it is below p0, the result is 0, otherwise 1. With enough shots the share of zeros approaches p0, but never exactly: real results always carry this statistical noise, on top of the hardware’s own errors.
Using a fixed seed makes the random numbers repeatable, which helps when checking work.
Write measure(state, shots, seed), which simulates that many shots and returns {0: count, 1: count}. Use rng = random.Random(seed) and rng.random().
All checks pass. Well done.
You finished this course. All courses
An AI tutor that gives hints, not answers. It sees your code, its output and this lesson. It can be wrong.