-
Notifications
You must be signed in to change notification settings - Fork 0
/
Random.java
36 lines (30 loc) · 815 Bytes
/
Random.java
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
35
36
public class Random {
java.util.Random gen = new java.util.Random();
Pages pages;
ReferenceString str;
int optCount[];
public Random(Pages pages) {
this.pages = pages;
}
public int simulate(ReferenceString str) {
this.str = str;
for (int i = 0; i < str.size(); i++)
if (!pages.hasSpace() && !pages.contains(str.get(i))) {
pages.remove(pages.get(gen.nextInt(pages.getRSS())));
pages.add(str.get(i));
}
else if (pages.hasSpace() && !pages.contains(str.get(i))) {
pages.add(str.get(i));
}
return pages.pageFaults;
}
public void print() {
pages.print();
}
public static void main(String[]args) {
Random random = new Random(new Pages(3));
ReferenceString str = new ReferenceString(.9, 10000);
str.fillRandomly();
System.out.println(random.simulate(str));
}
}