-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplace-random.c
34 lines (29 loc) · 1.34 KB
/
replace-random.c
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
30
31
32
33
34
/**
* CS 537 Programming Assignment 4 (Fall 2020)
* @file replace-random.c
* @brief Replacement module implementing a random replacement policy. Initially
* used for debugging but kept because it works
* @author Michael Noguera
*/
#include "replace.h"
#include <stdlib.h>
static int numPages;
void Replace_initReplacementModule(int numberOfPhysicalPages) {
numPages = numberOfPhysicalPages;
}
void* Replace_initOverhead(__attribute__((unused))VPage* vpage) { return NULL; }
void Replace_freeOverhead(__attribute__((unused)) void* o_ptr) { return; }
void Replace_notifyPageAccess(__attribute__((unused)) void* o_ptr) { return; }
void Replace_notifyPageLoad(__attribute__((unused)) void* o_ptr) { return; }
/**
* Randomly chooses a page to evict.
* @details Yes, this violates "MSC30-C Do not use the rand() function for
* generating pseudorandom numbers". However, true randomness is undesirable
* here because a) predicability of these numbers has no impact on security, and
* b) determinism is useful for testing. This does mean running the program
* multiple times may produce the same result. See
* https://wiki.sei.cmu.edu/confluence/display/c/ for details.
* @return index of page, within the interval [0, numberOfPages)
*/
unsigned long Replace_getPageToEvict() { return rand() % numPages; }
void Replace_freeReplacementModule() { return; }