-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.js
50 lines (46 loc) · 914 Bytes
/
Functions.js
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
50
import { Event } from './Classes.js';
export function checkIfLockerFaults(
quarter,
p,
costReturn,
l,
currTime,
P,
creatingPickup
) {
if (p.locker.fault) {
costReturn[l] += 1
creatingPickup(p, P)
} else {
const x = Math.random()
if (x < 0.01) {
p.locker.fault = true
costReturn[l] += 1
new Event(
quarter,
currTime + (Math.random() * (1/24 - 5/24) + 5/24),
3,
p,
P
)
} else {
if (p.lockersize == 0) {
p.locker.smallAvailable += 1
} else if (p.lockersize == 1) {
p.locker.mediumAvailable += 1
} else {
p.locker.largeAvailable += 1
}
}
}
}
export function poisson(mean) {
var L = Math.exp(-mean);
var p = 1.0;
var k = 0;
do {
k++;
p *= Math.random();
} while (p > L);
return k - 1;
}