-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.c
More file actions
29 lines (24 loc) · 781 Bytes
/
Random.c
File metadata and controls
29 lines (24 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "Page.h"
//Random Page Replacement Algorithm
page *RandomPageReplacement(LISTOFPAGES* ListOfPages)
{
// pointer to current page in the list, starting at the head
page* currentPage = ListOfPages->head;
// pointer will point to our random page after traversal
page* randomPage = NULL;
// get index of some random page in the list
int random_page_index = rand() % TOTAL_PAGE;
int index = 0;
// traverse to the randomly selected page
while (currentPage != NULL) {
// if we are at our random page, stop
if (index == random_page_index) {
randomPage = currentPage;
break;
}
// otherwise, continue traversal
index = index + 1;
currentPage = currentPage->next;
}
return randomPage;
}