See the comments for an explanation.
/**
* Generate random numbers at an interval
* @param perMinute - The number of numbers to generate per minute
* @param totalNumbers - The total number of numbers to generate
* @param minNumber - The minimum number to be generated
* @param maxNumber - The max number to be generated
*/
function randomNumberAtInterval(perMinute, totalNumbers, minNumber, maxNumber, cb){
var int = 60000 / perMinute;
var count = 0;
var interval = setInterval(()=>{
cb(Math.random() * (maxNumber - minNumber) + minNumber);
count++;
if(count >= totalNumbers) clearInterval(interval);
}, int);
}
// Will generate 7 numbers per minute
// until it has generated 14 numbers (so for 2 minutes)
// between 0 and 10
// and it will log the number to the console.
randomNumberAtInterval(7, 14, 0, 10, function(randomNumber){
console.log(randomNumber);
})
solved Generate random number in a minute [closed]