# Generate random 10-digit number

**URL:** <https://community.postman.com/t/generate-random-10-digit-number/39031>\
**Category:** Help Hub\
**Created:** [September 11, 2022, 7:16pm UTC](https://community.postman.com/t/generate-random-10-digit-number/39031 "2022-09-11T19:16:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hannahbroch](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@hannahbroch](https://community.postman.com/u/hannahbroch)\
**Post date:** [September 11, 2022, 7:16pm UTC](https://community.postman.com/t/generate-random-10-digit-number/39031/1 "2022-09-11T19:16:53Z")

</div>

I would like to create a dynamic variable - a random 10-digit number  
how do i do this?

---

<div class="post-metadata">

**Author:** ![cruxto](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@cruxto](https://community.postman.com/u/cruxto)\
**Post date:** [September 11, 2022, 7:52pm UTC](https://community.postman.com/t/generate-random-10-digit-number/39031/2 "2022-09-11T19:52:27Z")

</div>

Hi,

A simple way to do it, is to use the built-in library lodash.

e.g.  
const randomNumber = \_.random(1000000000,9999999999)

If you need to use it in a request, you can add this to a pre-request script like this:

const randomNumber = \_.random(1000000000,9999999999)  
pm.variables.set(‘randomNumber’, randomNumber )

then in the request body, add {{randomNumber}}

e.g.

```auto
{
    "username": "Test",
    " number": "{{randomNumber}}"
}

```

I hope this helps.

---

<div class="post-metadata">

**Author:** ![hannahbroch](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@hannahbroch](https://community.postman.com/u/hannahbroch)\
**Post date:** [September 15, 2022, 7:08am UTC](https://community.postman.com/t/generate-random-10-digit-number/39031/3 "2022-09-15T07:08:09Z")

</div>

amazing  
thank you very much!!

---

<div class="post-metadata">

**Author:** ![tui2518](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@tui2518](https://community.postman.com/u/tui2518)\
**Post date:** [July 16, 2023, 9:42pm UTC](https://community.postman.com/t/generate-random-10-digit-number/39031/4 "2023-07-16T21:42:30Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

_My question_:

_Details (like screenshots)_:

_How I found the problem_:

_I’ve already tried_:

---

<div class="post-metadata">

**Author:** ![cruxto](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@cruxto](https://community.postman.com/u/cruxto)\
**Post date:** [February 13, 2025, 9:54am UTC](https://community.postman.com/t/generate-random-10-digit-number/39031/5 "2025-02-13T09:54:47Z")

</div>

> [@cruxto](#):
>
> const randomNumber = \_.random(1000000000,9999999999)
> 
> If you need to use it in a request, you can add this to a pre-request script like this:
> 
> const randomNumber = \_.random(1000000000,9999999999)  
> pm.variables.set(‘randomNumber’, randomNumber )
> 
> then in the request body, add {{randomNumber}}
> 
> e.g.
> 
> ```auto
> {
> "username": "Test",
> " number": "{{randomNumber}}"
> }
> 
> ```

Update:

With lodash being deprecated from the built-in libraries, you must load it first.

const {random} = require(‘lodash’)

const randomNumber = random(1000000000,9999999999)  
pm.variables.set(‘randomNumber’, randomNumber )

or use native javascript like this:

function generateRandomNumber() {  
const min = 1000000000; // Minimum value  
const max = 9999999999; // Maximum value  
const randomNumber = Math.floor(Math.random() \* (max - min + 1)) + min;  
return randomNumber;  
}  
const randomNumber = generateRandomNumber();  
console.log(randomNumber);
