Jmeter random variable in several threads
Just put
12345678-1234-4444-a123-${__Random(111111111111,999999999999)}
inline where you need.
If you put this in your UDV component, value is assigned once only, before threads are even started. The behaviour is OK according to jmeter documentation. Please read it carefully.
Suppose you can simply use Random Variable configuration element instead:
Variable Name: uuid
Output Format: 12345678-1234-4444-a123-000000000000
Minimum Value: 111111111111
Maximum Value: 999999999999
Per Thread (User): True
Generated value
- can be accessed as
${uuid}
; - unique for each thread;
- preserved between different samplers calls flow of each thread (not regenerated during each reference);
- generated during each iteration of Thread Group.
Test Plan
Thread Group
Random Variable
...
Sampler 1
Sampler 2
...
e.g.
iteration: 1
thread: 1
sampler 1: VALUE_1-1
sampler 2: VALUE_1-1
...
thread: 2
sampler 1: VALUE_2-1
sampler 2: VALUE_2-1
...
...
iteration: 2
thread: 1
sampler 1: VALUE_1-2
sampler 2: VALUE_1-2
...
thread: 2
sampler 1: VALUE_2-2
sampler 2: VALUE_2-2
...
...
Sample script implemented for schema given above: rnd-var.jmx
As per Random Seed
field description of Random Variable:
Default is the current time in milliseconds. If you use the same seed value with Per Thread set to true, you will get the same value for earch Thread as per Random class.
If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers.
Keep it in mind on implementing scenarios with high concurrency (as mentioned below in comments).
To overcome this issue you can use randomize seed with e.g. ${__Random(MIN,MAX)}
as value of Seed for Random function
field.