How can I generate a random number each time a call is executed? (not using the feeder option)

I need to find a way to generate a random number each time the REST call is executed.

I have the following GET call:

    exec(http("Random execution")
      .queryParam("id", getRandomId()))

Obviously it doesn’t work as the random number is only generated once and I end up with the same number whenever this call is executed. I cant use the feeder option as my feeder is already huge and is generated by a 3rd party for each test.

As always the amazing James Warr sorted me out over at stack overflow


Method queryParam takes Expression as both arguments, which means it can be a lambda (anonymous function):
def queryParam(key: Expression[String], value: Expression[Any])


So if you want the value to be generated every time just use a lambda instead of a fixed value:

.queryParam(“id”, _ => getRandomId()))


If you need actual session instance to generate some dynamic value you can grab it from first argument:
.queryParam(“id”, session => getRandomId(session)))


This way Gatling will know it has a function instead of value and will call it every time the step is executed :slight_smile: