mardi 30 mai 2017

Generate a random boolean 70% True, 30% false

I have the following function that generates a random boolean. choose_direction: function () {

 var random_boolean = Math.random() >= 0.5;
    if (random_boolean) {
        trade.call()
        prev_trade.goingUp = true
        console.log('Trade: CALL!!!!!!!!!!!!!!!!!!!!!!')
    } else {
        trade.put()
        prev_trade.goingUp = false
        console.log('Trade: PUT!!!!!!!!!!!!!!!!!!!!!!!!')
    }
}

However, I need the distribution to be unfair. More specifically, I want the output to be 70% of the time true and 30% of the time false.




Aucun commentaire:

Enregistrer un commentaire