mardi 14 août 2018

Return random number excluding specific range - javascript

I'm trying to return a random number within a specific range while also excluding a specific range within it. I've seen similar questions posed, but I can't get it to work. Here's what I have so far:

var x = xFunction();

function xFunction() {
    return parseFloat(Math.round(Math.random() * 2250) / 1000).toFixed(3);  
}

if (x > 1.250 && x < 2.001 ) {
  // this number is excluded so redo xFunction();  
} else {
  // this number is acceptable so do some code
}

Any help is appreciated. Thank you so much!




Aucun commentaire:

Enregistrer un commentaire