Search code examples
scalagatling

How to generate Random Numeric String having 6 digits in Gatling?


I am new to Gatling and Scala Environment.

How to generate a Random Numeric String having 6 digits, in Gatling?

For example, I need to feed "123456" for an attribute in Gatling.

Thanks for the help.


Solution

  • You could start with what you've got and make the following change...

    ...filter(_.isDigit).take(6).mkString
    

    ...but I'd be more inclined toward the following.

    (Random.nextInt(900000)+100000).toString
    

    Note: For the 1st proposed solution, leading zeros are possible, "010203" for example. That's not the case for the 2nd. Not sure which is preferred.


    Scala 2.13.x option:

    util.Random.between(100000, 1000000)
    //minimum (inclusive)--^      ^--maximum (exclusive)