jeudi 29 juin 2017

javascript random value between two variables? [duplicate]

This question already has an answer here:

I have this function here:

function example() {
    totalNum -=(Math.floor(Math.random() * valMax) + valMin);
}

valMin and valMax are 3 & 6 after being calculated, defined like this:

var valMin = Math.ceil((Math.round(other numbers and vars here));
var valMax = Math.ceil((Math.round(other different numbers and vars here));

but when using that function, i get higher max value up to 8. But min seems to work fine.

What am i doing wrong? appreciate some help, thanks!!




Aucun commentaire:

Enregistrer un commentaire