How to Generate 4,6,8,10 Digit Random number in Node JS?

By Hardik Savani May 31, 2021 Category : Node JS

Hi,

Today our leading topic is node js generate random number between range. this example will help you how to generate random number in node js. let’s discuss about how to generate 4 digit random number in node js. if you have question about generate 6 digit random number nodejs then i will give simple example with solution.

In this example i will give you simple generate random number with 4 digit, 6 digit, 8 digit and 10 digit with node js project.

server.js

/**

* Write code on Method

*

* @return response()

*/

function betweenRandomNumber(min, max) {

return Math.floor(

Math.random() * (max - min + 1) + min

)

}

/*------------------------------------------

--------------------------------------------

Example

--------------------------------------------

--------------------------------------------*/

console.log(

"4 Digit: " + betweenRandomNumber(1000, 9999)

)

console.log(

"6 Digit: " + betweenRandomNumber(100000, 999999)

)

console.log(

"8 Digit: " + betweenRandomNumber(10000000, 99999999)

)

console.log(

"10 Digit: " + betweenRandomNumber(1000000000, 9999999999)

)

Output:

4 Digit: 1915

6 Digit: 339131

8 Digit: 79480217

10 Digit: 7112573214

i hope it can help you...

Tags :
Shares