JMeter functions generate dynamic values at the moment a sampler executes. Where User-Defined Variables and CSV Data Set Config produce values at iteration start, functions are evaluated inline — in a URL, a request body, a header value — every single time the element that contains them is processed.
Function syntax
All JMeter functions use this pattern:
${__functionName(arg1,arg2,varName)}
__functionName— the function identifier (note the double underscore)arg1,arg2— function-specific arguments (some functions take no arguments)varName— optional variable name; if provided, the result is also stored in${varName}for use later in the same iteration
Functions can be nested: ${__Random(1,${__P(maxId,1000)})} uses a property value as the upper bound for a random integer.
The Function Helper dialog
Before diving into individual functions, open Tools → Function Helper Dialog. This interactive builder lets you select a function, fill in its arguments, and generate the correct syntax — then copy it into your sampler or configuration field. It also shows a preview of the output. Use it whenever you are unsure of argument order.
Essential functions
Most-used JMeter functions — usage frequency in real test plans
__Random
Generates a random integer between min and max (inclusive).
${__Random(1,10000,productId)}
- Arg 1: minimum value
- Arg 2: maximum value
- Arg 3 (optional): variable name to store the result
Use cases: random product IDs in a URL, random quantities in an order body, random delay calculations.
URL path: /api/products/${__Random(1,5000,)}
Body: {"quantity": ${__Random(1,10,)}}
__time
Returns the current time as a formatted string or epoch milliseconds.
${__time(yyyy-MM-dd,today)}
${__time(HH:mm:ss,)}
${__time(,)} ← epoch milliseconds (no format arg)
${__time(yyyy-MM-dd_HH-mm-ss,timestamp)}
The format argument follows Java's SimpleDateFormat pattern. With no format argument, __time returns the current Unix timestamp in milliseconds — useful for unique IDs and correlation IDs.
__counter
Generates a sequential integer that increments by 1 each time it is evaluated.
${__counter(TRUE,orderId)} ← per-thread counter
${__counter(FALSE,globalId)} ← global counter across all threads
TRUE— each thread has its own counter, starting from 1. Thread 1 produces 1, 2, 3... Thread 2 independently produces 1, 2, 3...FALSE— a single counter shared across all threads, atomically incremented. Produces globally unique sequential numbers across the entire test run.
Use the global counter when you need truly unique sequential IDs even across parallel threads — for example, unique order numbers in a database.
__UUID
Generates a random UUID v4. No arguments required.
${__UUID}
Output example: f47ac10b-58cc-4372-a567-0e02b2c3d479
Ideal for: correlation IDs, idempotency keys, unique request identifiers that must not collide even across distributed test nodes.
__RandomString
Generates a random string of specified length from a given character set.
${__RandomString(12,abcdefghijklmnopqrstuvwxyz0123456789,token)}
- Arg 1: string length
- Arg 2: characters to sample from
- Arg 3: variable name
Use for: random usernames, random alphanumeric codes, random search terms.
__P
Reads a JMeter property by name, with an optional default.
${__P(baseUrl,https://staging.example.com)}
${__P(maxVUs,100)}
Already covered in the Variables and Properties lesson — this is the inline function equivalent of the UDV-based approach.
__CSVRead
Reads a specific column from a specific row in a CSV file, using a shared file pointer.
${__CSVRead(products.csv,0)} ← column 0 (first column) of next row
${__CSVRead(products.csv,1)} ← column 1 (second column) of same row
${__CSVRead(products.csv,*)} ← advance the pointer to next row
Less convenient than CSV Data Set Config for most use cases, but useful when you need fine-grained control over which column to read and when to advance the pointer.
Combining functions for realistic data
The real power of JMeter functions is combination. A unique email address per iteration per thread:
${__threadNum}_${__time(,)}_${__Random(1,9999,)}@test.com
A unique transaction reference:
TXN-${__time(yyyyMMdd,)}-${__counter(FALSE,txnCounter)}
An order body with varied quantities and random product selection:
{
"orderId": "${__UUID}",
"productId": ${__Random(1,10000,)},
"quantity": ${__Random(1,5,)},
"timestamp": "${__time(yyyy-MM-dd'T'HH:mm:ss,)}"
}When not to use functions
Functions are evaluated at execution time — every sampler execution that contains a function call re-evaluates the function. For high-throughput tests (thousands of requests per second), complex functions with heavy computation add measurable overhead.
For large-scale load tests:
- Pre-generate data in CSV files and use CSV Data Set Config — the lookup is O(1)
- Use the Counter config element instead of
__counter— the config element is more efficient for simple sequential IDs - Reserve runtime functions for small-scale tests, smoke tests, and debugging
⚠️ Common mistakes
- Using
${__time(,)}as a unique ID and expecting it to be unique across threads.__timereturns the current millisecond timestamp. Two threads executing simultaneously produce the same value. Combine it with${__threadNum}or${__UUID}to guarantee uniqueness:${__threadNum}_${__time(,)}. - Confusing
__counter(TRUE)with__counter(FALSE). Per-thread counters (TRUE) restart from 1 for every thread — thread 1 and thread 2 both produce the sequence 1, 2, 3... Global counters (FALSE) produce globally unique values but require careful thought about reset behaviour across test runs. - Nesting functions with mismatched commas. The comma is JMeter's function argument separator. A function argument that itself contains a comma — for example, a date format like
yyyy-MM-dd,HH:mm:ss— breaks argument parsing. Use${__time(yyyy-MM-dd'T'HH:mm:ss,)}with the T literal inside the format string to avoid the ambiguity.
🎯 Practice task
Add dynamic data generation to your test plan using JMeter functions.
-
Open your existing test plan. In the request body of a POST sampler, build a JSON payload using three different functions:
{"id": "${__UUID}", "ref": "ORD-${__counter(FALSE,)}", "ts": "${__time(,)}"}Run with 3 users, 3 loops (9 total iterations). Confirm in View Results Tree that every request body has a different UUID, a unique sequential
ORD-Nreference, and a timestamp. -
Construct a dynamic URL with a random product ID:
/api/products/${__Random(1,500,pid)}. After the request, add a JSR223 Post-Processor withlog.info("Fetched product: " + vars.get("pid")). Open the Log Viewer and confirm the product ID logged matches what was in the URL. -
Open Tools → Function Helper Dialog. Select
__RandomString. Configure it to generate a 16-character string using only uppercase letters and digits. Copy the generated syntax and paste it into a Header field asX-Session-Token. Run and verify the header appears with a different value on each request.