← Back to the playground
THE FIELD NOTES

A small lottery. A proportional share.

Tickets are scheduling weights. More tickets mean a higher chance of receiving the next CPU slice.

Turn weights into a decision

Give A 50 tickets, B 30, and C 20. The runnable set has 100 tickets: A owns zero-based positions 0–49, B owns 50–79, and C owns 80–99. Draw one ticket uniformly, find its owner, and run that process for a time quantum. Repeat at the next scheduling decision.

Expected does not mean promised

With the runnable set fixed, the next-turn probabilities are 50%, 30%, and 20%. Across N equal-length selections, the expected count for A is 0.5 × N. A particular seeded run can differ. Independent random selection does not guarantee a maximum wait, a particular next process, or perfect short-run balance.

For a fixed probability p, the chance of receiving no selections in N independent rounds is (1 − p)N. That becomes small as N grows, but it is not a deterministic waiting-time bound. Do not treat nonzero selection probability as a guarantee against every finite wait.

Why finite workloads look different

Processes with finite bursts leave the pool when they finish. Their ticket ranges disappear, so probabilities change. If A needs eight CPU units and B needs two, their completed workload necessarily contains 80% A and 20% B, regardless of their original tickets. Tickets affect how that work is interleaved and when jobs finish, not the amount of work requested.

What this simulator models

One CPU, abstract time units, zero context-switch cost, and a versioned seeded random generator. There is no I/O blocking, multi-core execution, ticket transfer, or compensation in the initial engine. The seed makes an example repeatable; it is not a cryptographic source of randomness.

Run the simulator, try equal tickets, or compare lottery with round robin. The academic reference is OSTEP: Scheduling, Proportional Share.

KEEP EXPLORINGUnderstand lottery scheduling ↗Lottery vs. round robin ↗Work through arrival times ↗