function betterRandom(probabilities) {
    let i,
        sum = 0,
        r = Math.random();
    for (i in probabilities) {
        sum += probabilities[i];
        if (r <= sum) return i;
    }
}
/**
 * Does random picking but with weights
 * @param {Object} probabilities
 */
Does random picking but with weights
@param {Object} probabilities
Does random picking but with weights @param { Object } probabilities
function betterRandom(probabilities) {
    let i,
        sum = 0,
        r = Math.random();
    for (i in probabilities) {
        sum += probabilities[i];
        if (r <= sum) return i;
    }
}
function betterRandom ( probabilities ) { let i , sum = 0 , r = Math . random ( ) ; for ( i in probabilities ) { sum += probabilities [ i ] ; if ( r <= sum ) return i ; } }
Does random picking but with weights
 @param {Object} probabilities
Does random picking but with weights @param { Object } probabilities