mardi 11 juillet 2017

Probability of getting 1 in JavaScript Math.Floor((Math.Random() * 1) + 0)

I got this code pattern from most pages on the front page of google search. My intention is to get either 0 or 1. My data is showing all zeroes. Is it safe to assume that this will never give 1? Right now I adjusted it to as below:

if(inclusiveUpperBound == 1 && inclusiveLowerBound == 0) {
    oneAdjust = 1;
}

if(!window.useRandomArray && (window.randomArray.length > 0)) {
    randomNumber = Math.floor((Math.random() * (inclusiveUpperBound+oneAdjust)) + (inclusiveLowerBound+oneAdjust)) - oneAdjust;
}




Aucun commentaire:

Enregistrer un commentaire