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

**URL:** <https://community.gatling.io/t/how-can-i-generate-a-random-number-each-time-a-call-is-executed-not-using-the-feeder-option/5469>\
**Category:** Gatling (Open-Source)\
**Created:** [February 2, 2020, 3:11pm UTC](https://community.gatling.io/t/how-can-i-generate-a-random-number-each-time-a-call-is-executed-not-using-the-feeder-option/5469 "2020-02-02T15:11:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ito](https://avatars.discourse-cdn.com/v4/letter/i/ec9cab/32.png) [@Ito](https://community.gatling.io/u/Ito)\
**Post date:** [February 2, 2020, 3:11pm UTC](https://community.gatling.io/t/how-can-i-generate-a-random-number-each-time-a-call-is-executed-not-using-the-feeder-option/5469/1 "2020-02-02T15:11:17Z")

</div>

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

I have the following GET call:

```auto
    exec(http("Random execution")
      .get("/randomApi")
      .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.

---

<div class="post-metadata">

**Author:** ![Ito](https://avatars.discourse-cdn.com/v4/letter/i/ec9cab/32.png) [@Ito](https://community.gatling.io/u/Ito)\
**Post date:** [February 4, 2020, 12:56pm UTC](https://community.gatling.io/t/how-can-i-generate-a-random-number-each-time-a-call-is-executed-not-using-the-feeder-option/5469/2 "2020-02-04T12:56:27Z")

</div>

As always the amazing James Warr [sorted me out](https://stackoverflow.com/questions/60027441/in-gatling-how-can-i-generate-a-random-number-each-time-a-call-is-executed-no/60031507#60031507) over at stack overflow

---

<div class="post-metadata">

**Author:** ![aartajew](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@aartajew](https://community.gatling.io/u/aartajew)\
**Post date:** [February 5, 2020, 9:39am UTC](https://community.gatling.io/t/how-can-i-generate-a-random-number-each-time-a-call-is-executed-not-using-the-feeder-option/5469/3 "2020-02-05T09:39:20Z")

</div>

Hi,

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 🙂

Cheers,  
Adam
