How to use random data in Postman
Introduction
When performing manual API testing, it is ideal to explore different scenarios for each endpoint, testing various data types, limits, and edge cases.
Comprehensive testing ensures that the endpoint remains robust under different conditions.
Using fixed data for endpoint tests can be counterproductive. Manual testing becomes too mechanical and lacks the unpredictability of varied data input.
In a daily workflow, it is easy to overlook specific tests—such as checking character limits for a name field or minimum/maximum constraints for a numeric field. Using random data solves this by introducing variety into your testing routine.
Postman
Postman is one of the most widely used tools for testing endpoints. It allows you to configure fields to send random data automatically using variables.
With this setup, every new request sends different data.
Dynamic Variables
Postman provides several built-in variables. The syntax is: {{$randomFullName}}.
When used in a request body, it looks like this:
{
"name": "{{$randomFullName}}"
}
Any of these pre-built variables can be used in your tests. They work in the request body as well as in route parameters.
Here are some common examples:
Personal Data
{{$randomFirstName}}: Random first name.{{$randomLastName}}: Random last name.{{$randomFullName}}: Random full name.{{$randomJobTitle}}: Random job title.{{$randomPhoneNumber}}: Random phone number.{{$randomEmail}}: Random email address.
Text Data
{{$randomLoremWords}}: Random words.{{$randomLoremSentence}}: Random sentence.{{$randomLoremParagraph}}: Random paragraph.
Location Data
{{$randomCity}}: Random city.{{$randomCountry}}: Random country.{{$randomZipCode}}: Random zip code.{{$randomLatitude}}: Random latitude.{{$randomLongitude}}: Random longitude.
Date Data
{{$timestamp}}: Current Unix timestamp.{{$randomDatePast}}: Random date in the past.{{$randomDateFuture}}: Random date in the future.
IDs and Numbers
{{$guid}}: Random GUID/UUID.{{$randomUUID}}: UUID version 4.{{$randomInt}}: Random integer (0 to 1000).{{$randomPrice}}: Random price.
Account and IP
{{$randomUserName}}: Random username.{{$randomPassword}}: Random password.{{$randomIP}}: Random IPv4 address.
Creating Custom Variables
If the built-in variables don't meet your needs, you can create your own.
Fixed Data
For information that remains constant across the project (like a standard header), use Environments. Assign a variable name and its value:
| variable | value | | :------- | :--------------- | | accept | application/json |
To use it, simply call (no $ sign needed).
Random Data
In the Pre-request Script tab, you can write custom scripts to generate random data.
const codeRandom =
"ABC-" + Math.random().toString(36).substring(7).toUpperCase();
pm.variables.set("myCodeRandom", codeRandom);
With this script, the variable becomes available to use anywhere in your request.
Conclusion
Using random data is essential for API testing. it reduces the "testing bias" of always using the same inputs.
It introduces the unpredictability needed to ensure all scenarios are covered and that the endpoint is truly reliable.
If you have any suggestions to improve this article, feel free to reach out to me on LinkedIn!