lundi 28 décembre 2015

Simple random function in an interval

It doesn't give me a value r in the given range? Why?

function getRandomIntInclusive(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

var x = window.prompt("minimo");
var y = window.prompt("maximo");
var r = getRandomIntInclusive(x,y);

console.log(r);

edit: This function has been taken from a link of dev mozilla Thank you




Aucun commentaire:

Enregistrer un commentaire