# Constant variable with random number

**URL:** <https://community.postman.com/t/constant-variable-with-random-number/21482>\
**Category:** Help Hub\
**Tags:** newman-project, variables, collections\
**Created:** [March 17, 2021, 10:53am UTC](https://community.postman.com/t/constant-variable-with-random-number/21482 "2021-03-17T10:53:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brahmajitammana](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@brahmajitammana](https://community.postman.com/u/brahmajitammana)\
**Post date:** [March 17, 2021, 10:53am UTC](https://community.postman.com/t/constant-variable-with-random-number/21482/1 "2021-03-17T10:53:06Z")

</div>

Hi All, I am newman here.

how can I have a same random integer in two tags in the body ?

for example:

```
{
"rollnumber" : "{{randomInt}}",
"studentNumber" : "{{randomInt}}"
}

```

I want to have a same random integer in both rollnumber and studentNumber

how to do that ?

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [March 17, 2021, 11:19am UTC](https://community.postman.com/t/constant-variable-with-random-number/21482/2 "2021-03-17T11:19:53Z")

</div>

@brahmajitammana Welcome to the community 💐

Under your pre-request script you need to assign the random variable to a specific variable (scope can be based on your req).

Under prerequest script, please paste this:

```auto
pm.environment.set('int', pm.variables.replaceIn('{{$randomInt}}'));

```

Now you can use the variable int in both places

```auto
{
"rollnumber" : "{{int}}",
"studentNumber" : "{{int}}"
}

Hope this solves your issue :blush:
```

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [March 17, 2021, 11:23am UTC](https://community.postman.com/t/constant-variable-with-random-number/21482/3 "2021-03-17T11:23:37Z")

</div>

In your pre-request script you can set a random number to a variable then use that variable in the body of your request.

**Pre-request**

```auto
const myRandomInteger = Math.floor(Math.random() * 1000);
pm.variables.set('myRandomInteger', myRandomInteger);

```

**Body**

```auto
{
  "rollnumber" : {{myRandomInteger}},
  "studentNumber" : {{myRandomInteger}}
}

```
