How to Generate 4,6,8,10 Digit Random number in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Node JS Find and Update Object in Array Example
- How to Get Data from Json File in Node JS?
- How to Remove Element from Array in Node JS?
- How to Push Element in Array in Node JS?
- How to use Underscore JS in Node JS App?
- Node JS Sort Array of Objects by Value Example
- Node JS Foreach Loop Array Example
- How to Create and Use .env File in Node JS?
- Axios HTTP requests in Node JS Example
- Node JS Make HTTP Delete Request Example
- Node JS Multer Rename Uploaded File Example