Search⌘ K

Simulator

Learn to simulate the lottery scheduling process, which assigns CPU time to jobs based on randomized ticket draws. Understand how to use random numbers to determine the winning ticket and run jobs accordingly. This lesson provides hands-on experience with computing lottery scheduler decisions and interpreting job queues to grasp probabilistic fairness in CPU scheduling.

We'll cover the following...

This program, lottery.py, allows you to see how a lottery scheduler works. As always, there are two steps to running the program. First, run without the -c flag: this shows you what problem to solve without revealing the answers.

prompt> ./lottery.py -j 2 -s 0
...
Here is the job list, with the run time of each job: 
  Job 0 ( length = 8, tickets = 75 )
  Job 1 ( length = 4, tickets = 25 )

Here is the set of random numbers you will need (at most):
Random 511275
Random 404934
Random 783799
Random 303313
Random 476597
Random 583382
Random 908113
Random 504687
Random 281838
Random 755804
Random 618369
Random 250506
]
Terminal 1
Terminal
Loading...

When you run the simulator in this manner, it first assigns you some random jobs (here of lengths 8, and 4), each with some number of tickets (here 75 and 25, respectively). The simulator also gives you a list of random numbers, which you will need to determine what the lottery scheduler will do. The random numbers are chosen to be between 0 and a large number; thus, ...