# \[Gatling2\] adding random int as query param

**URL:** https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649
**Category:** Gatling (Open-Source)
**Created:** [November 5, 2013, 10:34am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649 "2013-11-05T10:34:03Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Uladzimir\_Kazimirchy](https://avatars.discourse-cdn.com/v4/letter/u/f14d63/32.png) [@Uladzimir\_Kazimirchy](https://community.gatling.io/u/Uladzimir_Kazimirchy)
#### Post date: [November 5, 2013, 10:34am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/1 "2013-11-05T10:34:03Z")

</div>

Hi!

I need to avoid server request caching so i decided to add a random int as query param to urls.  
I’m trying to add additional parameter via .queryParam(“param”, “value”) and use

_ThreadLocalRandom.current.nextInt(1000)_ as a random number generator. The problem is –

when I add .toString and pass this value to .queryParam I get an error:

type mismatch;  
found : () =\> String  
required: io.gatling.core.session.Session =\> io.gatling.core.validation.Validation[String]  
13:25:58.444 [ERROR] i.g.a.ZincCompiler$ - .queryParam(“testParam”, ThreadLocalRandom.current.nextInt(1000).toString)

What am I doing wrong…?

Thanks.

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [November 5, 2013, 10:54am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/2 "2013-11-05T10:54:49Z")

</div>

Hi,

This indeed fails to compile with 2M3a but compiles fine with master, not sure why…

Anyway, this won’t work as you expect because you’re passing a value, not a function, ie it will be only evaluated once, when the scenario is built, not every time a request is built and sent.

long form: .queryParam(“testParam”, (session: Session) =\>ThreadLocalRandom.current.nextInt(1000).toString)  
can omit session type as the compiler can infer it: .queryParam(“testParam”, session =\>ThreadLocalRandom.current.nextInt(1000).toString)  
session is not used here anyway: .queryParam(“testParam”, \_ =\>ThreadLocalRandom.current.nextInt(1000).toString)

Cheers,

Stéphane

---

<div class="post-metadata">

### Author: ![Uladzimir\_Kazimirchy](https://avatars.discourse-cdn.com/v4/letter/u/f14d63/32.png) [@Uladzimir\_Kazimirchy](https://community.gatling.io/u/Uladzimir_Kazimirchy)
#### Post date: [November 5, 2013, 11:12am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/3 "2013-11-05T11:12:12Z")

</div>

Stéphane,

so I need something like this:

val httpProtocol = http.baseURL(“[http://some.url.com](http://some.url.com)”)

def getRand(i: Int) : String = ThreadLocalRandom.current.nextInt(i).toString

val scn = scenario(“Load test”)  
.feed(csv(“test\_data.csv”).random)  
.exec(http(“srvc\_call”).get("${url}")  
.queryParam(“testParam”, getRand(1000))  
.check(status.is(200))  
)

Right?

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [November 5, 2013, 11:13am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/4 "2013-11-05T11:13:57Z")

</div>

Nope, getRand(1000) will still be evaluated once.  
\_ =\> getRand(1000)

---

<div class="post-metadata">

### Author: ![Uladzimir\_Kazimirchy](https://avatars.discourse-cdn.com/v4/letter/u/f14d63/32.png) [@Uladzimir\_Kazimirchy](https://community.gatling.io/u/Uladzimir_Kazimirchy)
#### Post date: [November 5, 2013, 11:17am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/5 "2013-11-05T11:17:13Z")

</div>

and now I get ClassNotFoundException

java.lang.reflect.InvocationTargetException  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:606)  
at scala\_maven\_executions.MainHelper.runMain(MainHelper.java:164)  
at scala\_maven\_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)  
Caused by: java.lang.ClassNotFoundException: performance.img\_srvc.Img\_perftest.scala  
at scala.tools.nsc.interpreter.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:69)  
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)  
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)  
at io.gatling.app.SimulationClassLoader$$anonfun$simulationClasses$1.apply(SimulationClassLoader.scala:56)  
at io.gatling.app.SimulationClassLoader$$anonfun$simulationClasses$1.apply(SimulationClassLoader.scala:55)  
at scala.Option.map(Option.scala:145)  
at io.gatling.app.SimulationClassLoader.simulationClasses(SimulationClassLoader.scala:55)  
at io.gatling.app.Gatling.start(Gatling.scala:174)  
at io.gatling.app.Gatling$.fromMap(Gatling.scala:59)  
at io.gatling.app.Gatling$.runGatling(Gatling.scala:80)  
at io.gatling.app.Gatling$.main(Gatling.scala:54)  
at io.gatling.app.Gatling.main(Gatling.scala)

That drives me crazy 🙂  
What could be the reason?

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [November 5, 2013, 11:22am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/6 "2013-11-05T11:22:47Z")

</div>

o\_O

Is performance.img\_srvc the expected package name and Img\_perftest the expected Simulation class name?  
Is performance/img\_srvc a valid folder hierarchy?

---

<div class="post-metadata">

### Author: ![Uladzimir\_Kazimirchy](https://avatars.discourse-cdn.com/v4/letter/u/f14d63/32.png) [@Uladzimir\_Kazimirchy](https://community.gatling.io/u/Uladzimir_Kazimirchy)
#### Post date: [November 5, 2013, 11:29am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/7 "2013-11-05T11:29:57Z")

</div>

Yes. I guess if it was wrong then I should get the same error earlier(instead of Type Mismatch one).  
But when I corrected the error with types in .queryParam - I got this one. That’s strange…

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [November 5, 2013, 11:35am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/8 "2013-11-05T11:35:34Z")

</div>

At this point, I can’t help you find out what’s wrong with getting my hands on your files.  
Can you share?

---

<div class="post-metadata">

### Author: ![Uladzimir\_Kazimirchy](https://avatars.discourse-cdn.com/v4/letter/u/f14d63/32.png) [@Uladzimir\_Kazimirchy](https://community.gatling.io/u/Uladzimir_Kazimirchy)
#### Post date: [November 5, 2013, 11:35am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/9 "2013-11-05T11:35:55Z")

</div>

My bad, sorry. I added .scala extension to class name when running by maven.  
So it was looking for scala class 🙂

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [November 5, 2013, 11:37am UTC](https://community.gatling.io/t/gatling2-adding-random-int-as-query-param/649/10 "2013-11-05T11:37:58Z")

</div>

Ahhhhhhh 🙂
