Varsha
Varsha

Reputation: 1

How to write random function using Beanshell postprocessor using JMeter

I Have 3 set of correlation variables dependent on each other.

If I send 1st occurrence for 1 value then I need to send same to remaining values as well. Every time I need to pick random value.

So I need to write random function for one of the value id_matchnr and need to same it variable (var) and passing it to other variables (id_details_var , id_details2_Var)

I tried using below functions but none of them worked

int count = ${__Random(1,counter,)};

int count = ThreadLocalRandom.current().nextInt(1, counter);

math.random(1,counter)

Upvotes: 0

Views: 62

Answers (1)

Dmitri T
Dmitri T

Reputation: 168147

  1. Don't use Beanshell, it's some form of a performance anti-pattern. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language. More information: Apache Groovy: What Is Groovy Used For?

  2. It looks like you don't need any scripting at all, you can generate a random number and save it into a JMeter Variable using __Random() function

    enter image description here

Upvotes: 0

Related Questions