-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpusim.py
More file actions
49 lines (42 loc) · 1.1 KB
/
cpusim.py
File metadata and controls
49 lines (42 loc) · 1.1 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import time
import random as rand
import math
def burstnumber(input):
input = input * 100
input = math.trunc(input)
input += 1
return input
print("Testing")
r = rand.random()
print(r)
bursttest = 0.0856756876765
bursttest = burstnumber(bursttest)
print(bursttest, "This should be 9")
min = 0
max = 0
sum = 0
#replace l with argv[3]
#replace upperbound with argv[4]
iterations = 10000000
l = 0.001
upperbound = 3000
for i in range(iterations):
#replace random() with drand48
r = rand.random() #/ * uniform # dist[0.00, 1.00) -- also check out random() * /
x = -math.log(r) / l# / lambda; / * log() is natural log * /
# / * avoid values that are far down the "long tail" of the distribution * /
if (x > upperbound):
i -= 1
continue
if (i < 20):
print("x is ", x)
sum += x
if (i == 0 or x < min):
min = x
if ( i == 0 or x > max ):
max = x
avg = sum / iterations
print( "minimum value: ", min)
print( "maximum value: ", max)
print( "average value: ", avg)