Random Number generator trouble

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(202))
).pause(1 second)

}

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

-Santhosh

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)

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