0
I am mounting a result simulator of football game from some variables.
The logic is as follows: Every minute both teams have a chance to score a goal. This probability is calculated using some variables such as player’s note, tactics used, among others.
Assuming that Team A has an 8% probability of making a goal every minute, how can I calculate this probability and return values 1 for goal or 0 for no goal?
Something like that:
//VARIÁVEIS
var gol = 0;
var probabilidade = 0.8;
var tempo = 0;
var fimdejogo = 45;
//FUNÇÃO DE TEMPO E GOL
function TempoDeJogo() {
while (tempo < fimdejogo) {
tempo++;
//FUNÇÃO DA PROBABILIDADE
if (retorno_da_probabilidade == 1) {
gol++;
console.log(tempo, gol);
}
}
console.log("Fim de Jogo");
}
TempoDeJogo();
if (Math.random() <= probabilidade)
... OBS:0.8
is 80%, not 8%.– bfavaretto
Show!!! , exactly what I needed, and thanks for the Obs, the 80% had not touched me...
– Leandro Teraoka