How can I create a random value?

How can I create a random value?

For example, body:

{

“Code”: {{param}},

“Name”: random value

}

@Kyortush_13 You need to use dynamic variables.

For example if you need random first name,

{

“Code”: {{param}},

“Name”: {{$randomFirstName}}

}

Once you type the $ symbol you can see the list of random variables listed.

1 Like

One of the simplest methods, other than maybe using the postman built in random values, is to generate a number from the date and time. I like to add a prefix of something meaningful, to differentiate from other random values.

pm.environment.set('MYRANDOMVALUE',"RND"+String((new Date()).getTime()).replace(/\compD/gi,'').substring(7));

or if you don’t want to save it as a variable and just use it within the request, you could simply create it as a local variable

var myRandomValue = "RND"+String((new Date()).getTime()).replace(/\compD/gi,'').substring(7));
1 Like