Leading zeros in a random number generator for a feeder

What I am trying to do is to generate a feeder to give me email addresses in the form



What I current have is

val feeder=Iterator.continually(Map("email"->("testemail_"+ (Random.nextInt(20000)+"@test.com"))))

That generates in the format


So after looking through scala documentation, that suggests using lpad, but it appears that lpad is not supported in Gatling. So I’m currently got

val feeder=Iterator.continually(Map("email"->("testemail_" + (lpad(Random.nextInt(20000).toString, 5, 0) + "@test.com"))))

Which generates an error about unknown value lpad. Is there a better way of achieving leading zeros with gatling. I haven’t seen anything in the documentation for gatling that seems to deal with leading zeros outside of a println, which I don’ think will work with the above feeder structure.

Many thanks, Ian

AFAIK, Scala doesn’t have a built-in lpad, but that’s pretty easy to implement:

def lpad(s: String, len: Int, c: Char): String =
c.toString * (len - s.length) + s

Thank you for that - that works perfectly.

Kind regards, Ian

I use the following to add leading zero: