Today you build the packetizer yourself. Split a message into numbered packets, send them across a network that loses some on purpose, put them back together, and resend what’s missing.
No reading — build. Keep 6.4 (packets and TCP), 3.6–3.8 (lists and traversal), and 3.17 (random values) open. Your teacher hands out the Lab 6.5 spec today.
Internet, in code. Your simulation will behave like the real thing: lost packets, retries, and a delivery time that climbs as the network gets worse.
1. Split. Turn a message string into a list of numbered packets.
2. Send. Write a procedure with a parameter (the loss rate) that randomly decides whether each packet survives.
3. Reassemble. Put the survivors in order and find which numbers are missing.
4. Resend. Keep resending missing packets until the message is complete. Count every retransmission.
5. Measure. Run it at several loss rates and chart loss rate vs. retransmissions.
Here is the one new move — a procedure that succeeds some percent of the time — in a different costume: free throws. Your lab uses the same shape for packets.
import random def shot_made(percent): return random.randint(1, 100) <= percent makes = 0 for i in range(10): if shot_made(70): makes = makes + 1 print(makes)
PROCEDURE shotMade(percent)
{
RETURN (RANDOM(1, 100) ≤ percent)
}
makes ← 0
REPEAT 10 TIMES
{
IF (shotMade(70))
{
makes ← makes + 1
}
}
DISPLAY(makes)RANDOM(1, 100) ≤ 70 is true for 70 of the 100
equally likely values — a 70% chance. For a packet that’s lost 20% of the time, which
comparison would you write? Decide before you code.A network with a loss rate you choose. Each round, every packet not yet delivered is sent; some get lost. Run it several times at the same rate — random means the count changes.
This is a sanity check, not your lab. Your program should behave the same way — 0% loss means zero retransmissions, and higher rates mean more rounds.
| Turn in | What it must show |
|---|---|
| Your program | A list of packets; a procedure with a loss-rate parameter that uses a random value; selection; iteration; retransmission until complete. |
| Your chart | Loss rate on the x-axis, retransmissions on the y-axis, at least four rates. y-axis starts at zero (5.8). |
| One sentence | What the chart shows — and only what it shows. One run per rate is noisy; say so if that’s what you did. |
Four questions on the patterns you’re about to code.