Code from OSTEP chapter Scheduling: Proportional Share.
Compile with:
prompt> gcc -o lottery lottery.c -Wall
Run like this:
./lottery 1 100
which uses random seed '1' to run a little lottery 100 different times.
Read the source code for details.