title: How to dynamically generate JSon in Gatling?
body: <p>I have the following two methods:</p>
  
  <pre><code>def randomStartMethod() : Long = {
    var range = 1000L
    var r = ThreadLocalRandom.current().nextLong(10L*range)
    var randomStart = 1396024675000L + r
    return randomStart
  }
  
  def randomStopMethod() : Long = {
    var range = 1000L
    val r = ThreadLocalRandom.current().nextLong(10L*range)
    val randomStop =  1396024675000L + r*2L
    return randomStop
  }
  </code></pre>
  
  <p>Then I add it to the request body like this:</p>
  
  <pre><code>val activity = repeat(10, "i") {
        exec(http("POST activity post")
          .post("/activity/")
          .header("Content-Type", "application/json; charset=ISO-8859-1")
          .header("accept", "*/*")
          .body(StringBody(
            s"""
               |{
               |    "id": "activityId",
               |    "type": "run",
               |    "start_epoch_ms": "${randomStartMethod()}",
               |    "end_epoch_ms": "${randomStop()}",
               |    "metrics": [
               |        {
               |            "type": "distance",
               |            "unit": "KM",
               |            "source": "nike.running.ios",
               |            "values": [
               |                {
               |                    "start_epoch_ms": "${randomStartMethod()}",
               |                    "end_epoch_ms": "${randomStopMethod()}",
               |                    "value": 2.0
               |                }
               |
              |            ]
               |        }
               |    ]
               |}
            """.stripMargin)).
          asJSON
          .check(status.is(202))
          .check(
            jsonPath(
              "$.activityId").saveAs("message")
          )
          .check(bodyString.
            transform(_.split("\""
            )(3)).saveAs(
            "changeToken"))
  
        ).exec(
          session =&gt; {
            val maybeId =
              session.get(
                "message").asOption[String]
            println(maybeId)
            session
          }
        )
      }
    }
  </code></pre>
  
  <p>But here the values are not generated dynamically when I use with feed. Can someone suggest how to generate the random numbers every time throughout the run?</p>