JMeter – Random Variable

JMeter - Random Number

In JMeter, ‘Random Variable’ config element is used to generate random integer value between a specified range for each iteration. The generated value can be concatenated with a string which is stored in a variable as a string. Refer to the below screenshot, in which ‘rand_CustomerID’ is a random variable which will store a string value like custXXXXX; where XXXXX is any random value between 1 to 99999:

JMeter - Random Variable
Figure 01

How to add ‘Random Variable’ in JMeter?

You can follow steps to add Random Variable config element:

  1. Select ‘Test Plan’ node
  2. Right-click on the ‘Test Plan’ node
  3. Hover the mouse on ‘Add’
  4. Hover the mouse on ‘Config Element
  5. Click ‘Random Variable’ 

What are the input fields of ‘Random Variable’?

“Random Variable” has the following input fields:

  1. Name: To provide element name
  2. Comments: To provide arbitrary comments (if any)
  3. Variable Name: The name of the variable to store the generated random value. The value can be called using the same variable name anywhere in the test script. Example: ${rand_CustomerID}.
  4. Output Format: You can specify the format of the string. In the above example; if 12345 value is randomly generated then cust12345 will be the string. If nothing is specified then randomly generated value will be passed as it is.
  5. Minimum Value: The minimum value of the random number range.
  6. Maximum Value: The maximum value of the random number range.
  7. Seed for random function: The seed for the random number generator. The default is the current time in milliseconds. By providing the seed, you instruct JMeter to generate the random value in the same order in each test.
  8. Per Thread(User): If it is ‘False’, then the generated value will be shared between all threads in the thread group. If it is ‘True’, then each thread has its own value.

Leave a Reply

Your email address will not be published. Required fields are marked *