How can I create a random(seed) function using a custom seed for Jmeter?

26 views Asked by At

how do I implement a random function based on a custom seed?

I need to create a random generator function/component for jmeter based on a custom seed to be able to exactly reproduce a test run which uses __RandomFunctions(). It should work the same way as built in random functions like __RandomDate() etc but based on an initial random seed.

Looking into the Jmeter source it looks like all built in random functions (__RandomDate etc) use ThreadLocalRandom which don't use a custom seed. I also looked into creating a Plugin but that will not help as I need to use it as a function from various samplers. So which is the best way to instantiate a new Random object with a seed and then call it with random.nextLong from various samplers. It doesn't need to be global, a random object per thread is fine. How can I do this the easiest way?

1

There are 1 answers

4
Ivan G On BEST ANSWER
  1. You can use __groovy() function for that, something like:

    ${__groovy(new Random(12345).nextInt(),)}
    
  2. You can write your own JMeter Plugin implementing the above functionality

  3. You can request an enhancement

  4. You can suggest a contribution to existing Random function to introduce "seed" parameter