aboutsummaryrefslogtreecommitdiff
path: root/src/cosmic-cargo/static/random.js
blob: 152db0a0bd6fbeadc2ee12d61adf8483fff5d5d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function random_choice(arr){
    return arr[random_int(arr.length)];
}

function random_int(max) {
    return Math.floor(Math.random() * max);
}

function random_chance(percentage_of_success){
    return Math.random() < percentage_of_success;
}

function shuffle_array(array) {
    for (let i = array.length - 1; i > 0; i--) {
        const j = random_int(i + 1);
        [array[i], array[j]] = [array[j], array[i]];
    }
}