Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add print_stats to lottery.c to show the result statistics #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cpu-sched-lottery/lottery.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ int gtickets = 0;

struct node_t {
int tickets;
int count;
struct node_t *next;
};

Expand All @@ -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[])
{
Expand Down Expand Up @@ -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;
}