# Avoid double values for random environment variable

**URL:** <https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [September 16, 2020, 7:27am UTC](https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913 "2020-09-16T07:27:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgehrer](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bgehrer](https://community.postman.com/u/bgehrer)\
**Post date:** [September 16, 2020, 7:27am UTC](https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913/1 "2020-09-16T07:27:50Z")

</div>

Hi there

const OrderId = Math.floor((Math.random() \* 100) + 1);

pm.environment.set(“OrderId”,OrderId);

I’m using the following pre-request script to generate random env. variable. The problem is, that my collection should run every other day and it seems that sometimes the same random value is reused in sometimes.

Does somebody know a solution to avoid that the same random value is generated twice?

Thanks a lot and greetings

Benjamin

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 16, 2020, 8:02am UTC](https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913/2 "2020-09-16T08:02:28Z")

</div>

Does it need to a specific value?

You could use a guid if not.

```auto
pm.environment.set(“OrderId”, pm.variables.replaceIn('{{$guid}}'));

```

---

<div class="post-metadata">

**Author:** ![bgehrer](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bgehrer](https://community.postman.com/u/bgehrer)\
**Post date:** [September 16, 2020, 8:46am UTC](https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913/3 "2020-09-16T08:46:32Z")

</div>

Hi Danny

Thanks for your reply - yes i do need a numeric value…so de guid would not be possible…

Any other idea?

Greetings Benjamin

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 16, 2020, 9:02am UTC](https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913/4 "2020-09-16T09:02:31Z")

</div>

How about `{{$timestamp}}`?

That _should_ be a unique value each time 😁

---

<div class="post-metadata">

**Author:** ![bgehrer](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bgehrer](https://community.postman.com/u/bgehrer)\
**Post date:** [September 16, 2020, 9:29am UTC](https://community.postman.com/t/avoid-double-values-for-random-environment-variable/15913/5 "2020-09-16T09:29:53Z")

</div>

Thanks Danny! You are great! Works perfectly well!

Greetings Benjamin
