Avoid double values for random environment variable

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

Does it need to a specific value?

You could use a guid if not.

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

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

How about {{$timestamp}}?

That should be a unique value each time :grin:

1 Like

Thanks Danny! You are great! Works perfectly well!

Greetings Benjamin

1 Like