FAQs »

Can I generate a random string, number, or UUID/GUID in my script?

Sometimes it’s necessary to generate a random string, number, or UUID/GUID in your load test script.

To do this, you can call any of these functions:

  • randomalpha(len) - Generates a random alphabetic string of the specified length (consisting of all ASCII letters).
  • randomnumeric(len) - Generates a random numeric string of the specified length (consisting of digits 0-9).
  • randomalphanumeric(len) - Generates a random alphanumeric string of the specified length (consisting of all ASCII letters and digits 0-9 at random).
  • uuid() - Generates a 128-bit UUID in the form of a hyphenated hexadecimal string (8-4-4-4-12), for a total of 36 characters.

These functions can only be called from within an ${} expression, similar to referencing a variable. For example:

GET https://petstore.loadster.app/api/inventory?q=${randomalpha(2)}

The ${randomalpha(2)} section of this URL will be substituted at runtime with a random string of 2 letters.

More information is available in Variables & Expressions.

When would it make sense to use random data?

Dynamic POST or PUT bodies

Load testing a dynamic web application or API often requires that your script create resources on the server or submit a web form via an HTTP POST or PUT request.

It’s usually a good idea to submit different data with each such request. To do this, you can either use a dataset with predefined values, or generate the data randomly on the fly with an expression.

Cache busting

It’s common for busy sites to be situated behind a caching proxy or web application firewall that caches identical-looking requests to keep them from hitting your application servers. If you need to ensure that your load test traffic hits the actual servers, bypassing such a caching layer, you can add random query strings to the URLs to make them dynamic. For example:

GET https://petstore.loadster.app/?_=${randomalpha(16)}

In this URL we’ve employed an underscore query parameter with a random value, to make sure each request is different, thereby bypassing the caching layer.