I am trying to make a number simulation that functions as follows:
- Begins at baseline value
- Generates random value within given range of baseline
- Takes generated value and generate another value within same range
- All generated values remain within a larger range
So if I have a starting value of 5, I need it to generate a number within a range of say 2. It then needs to take that value (between 3 and 7) and generate another number with the same range of 2, and so on. But I also need any numbers generated to stay between 0 and 10.
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;
}
.toFixed(6), which means you want to return astringwith 6 decimals? If you want to chain call your function, better return a number no?