diff --git a/cpu-sched-lottery/lottery.c b/cpu-sched-lottery/lottery.c index a4ef241..63e0f91 100644 --- a/cpu-sched-lottery/lottery.c +++ b/cpu-sched-lottery/lottery.c @@ -8,6 +8,7 @@ int gtickets = 0; struct node_t { int tickets; + int count; struct node_t *next; }; @@ -32,6 +33,15 @@ void print_list() { printf("\n"); } +void print_stats(int loops) { + struct node_t *curr = head; + printf("Stats:\n"); + while (curr) { + printf("[%d]: %.3f %%\n", curr->tickets, (curr->count * 1. / loops) * 100); + curr = curr->next; + } +} + int main(int argc, char *argv[]) { @@ -67,8 +77,10 @@ main(int argc, char *argv[]) // current is the winner: schedule it... print_list(); printf("winner: %d %d\n\n", winner, current->tickets); + current->count += 1; } + print_stats(loops); return 0; }