# Random Number generator trouble

**URL:** <https://community.gatling.io/t/random-number-generator-trouble/1384>\
**Category:** Gatling (Open-Source)\
**Created:** [September 9, 2014, 3:38am UTC](https://community.gatling.io/t/random-number-generator-trouble/1384 "2014-09-09T03:38:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santhosh](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Santhosh](https://community.gatling.io/u/Santhosh)\
**Post date:** [September 9, 2014, 3:38am UTC](https://community.gatling.io/t/random-number-generator-trouble/1384/1 "2014-09-09T03:38:31Z")

</div>

Hi,

I am trying to generate random number below. It is generating same number over and over\*\*.\*\* please help me with this.

val r1 = new Random(10000000000)

val scn = scenario(“Load Test”)  
.during(500 seconds)  
{  
exec(

http(“POST Activity “)  
.post(”/v1”)  
.headers(custom\_header)  
.headers(Map[String, String](“userid” → **r1.nextLong().toString**))  
.body(ELFileBody(“Payload.json”))  
.check([status.is](http://status.is/)(202))  
).pause(1 second)

}

setUp(  
scn.inject(  
rampUsers(1) over (60 seconds)  
)  
).protocols(httpConf)

-Santhosh

---

<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:** [September 9, 2014, 5:43am UTC](https://community.gatling.io/t/random-number-generator-trouble/1384/2 "2014-09-09T05:43:37Z")

</div>

Many issues with your code:

1. You’re passing a VALUE, that gets evaluated only once, when the Simulation is built. You have to pass a function, i.e. something that will wrap a block of code so that it will be evaluated every time needed.
2. You should probably use a ThreadLocalRandom
3. Why use headers for passing a single value? Just use header.

.headers(“userid”, session =\> **r1.nextLong().toString**)

---

<div class="post-metadata">

**Author:** ![Santhosh](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Santhosh](https://community.gatling.io/u/Santhosh)\
**Post date:** [September 10, 2014, 6:17pm UTC](https://community.gatling.io/t/random-number-generator-trouble/1384/3 "2014-09-10T18:17:39Z")

</div>

Thanks Stephane. I implemented your suggestions and also removed .during() from the scenario, placed the steady time in setUp and it worked.
