How to generate a Random Number of required length

My question: I would like to generate a random number in the given range.
For eg: I would like to generate a value between 234545 and 5565756

I’ve already tried: YES

Hello there,

to generate a random number between 234545 and 5565756, you can do like this.

function randInt(min, max) {
   return Math.round((Math.random() * Math.abs(max - min)) + min);

console.log("Random integer: " + randInt(234545, 5565756));

I hope it’ll help you.
Best Regards,
Rishi Purwar


Thank you for your quick reply


@tulasi Welcome to the Community :partying_face:

You can create function like below,

let min = 234545;
let max = 5565756;
// for generating random number 
function randomNumber(min, max) { 
    return Math.random() * (max - min) + min;
console.log(Math.round(randomNumber(min, max)));

to reuse it

Else you can directly use

console.log(Math.round(Math.random() * (5565756 - 234545) + 234545));

And assign this to another variable as per your needs :blush:

1 Like

Thank you very much for your quick support. I am new to PostMan

1 Like

I saw @thefierycoder’s reply after posting :raised_hands: Both are same :blush:

1 Like

@bpricilla Can you please help me with this?

1 Like

@tulasi No worries at all!! We too started in your place once :blush:

All the best for your learning :partying_face:

1 Like