How to generate a random double number between min and max in Node.js

1 Answer

0 votes
function generateRandomDoubleNumberMinMax(min, max) {
    // Math.random() static method returns a floating-point, 
    // that's greater than or equal to 0 and less than 1
    return Math.random() * (max - min + 1) + min;
}
 
const min = 70;
const max = 90;
 
const d = generateRandomDoubleNumberMinMax(min, max);
 
console.log(d);
 
 
 
/*
run:
 
81.68728432177187
 
*/

 



answered Jul 23, 2024 by avibootz

Related questions

1 answer 104 views
1 answer 145 views
1 answer 127 views
1 answer 120 views
1 answer 123 views
...