-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonkyMath.js
38 lines (32 loc) · 995 Bytes
/
fonkyMath.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
//get random Int smaller than max
export function getRandomIntMax(max) {
return Math.floor(Math.random() * max);
}
//get random Int between min and max
export function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
export function getRandomArbitraryMax(max) {
return Math.random() * max;
}
export function smoothing(number) {
if (number < 0.2) {
return number * 2;
}
else if (number > 0.8) {
return number * 2 - 1;
}
else {
return number / 2 + 0.25;
}
}
export function getRandomIntMaxSmoothing(max) {
return Math.floor(smoothing(Math.random()) * max);
}
export function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min); // The maximum is inclusive and the minimum is inclusive
}