vendredi 9 février 2018

Javascript: Generate random number using a range inside a range

I am trying to make a number simulation that functions as follows:

  1. Begins at baseline value
  2. Generates random value within given range of baseline
  3. Takes generated value and generate another value within same range
  4. All generated values remain within a larger range

I can use random() with a single defined range, but I don't know how to do two:

function generateValue(min, max) {
    var max = 2,
        min = 0,
        value = (Math.random() * (max - min) + min).toFixed(6);
    return value;
}




Aucun commentaire:

Enregistrer un commentaire