Issue with Random generator

Hi
I have observed an issue with my random generator in which i am using timestamp to create accounts for my simulation.But when i have checked gatling.log for errors from our application end,it showed few accounts which got created based on timestamp as DUPLICATE accounts.Below is the script line i used

If you are running for multiple users for account creation, the best approach would be.
1.time in mill seconds
2.some random chars
3.some random numbers

val fdeerdb=<currenttimemills + +

This could eliminate duplicate values and always give unique email id

e.g. gatlingtest1564207255ABC987@loadtest.com

Thanks Mohan… is there any random number generator only specified to generate random numbers just like the below
Random.alphanumeric.take(4).

I need generator only for numbers avoiding alphabets.Help me on this

My solution to that problem was to create a class for generating timestamps. In the class, I remember the last timestamp I generated. When I generate a new timestamp, I look at the current time. If that number is not greater than the saved number, then I increment the saved timestamp and return that, otherwise, I save the current time as the last timestamp and return it. Key point: the timestamp generation code has to be synchronized.

The above guarantees uniqueness, at the cost of having a tiny bit of code in a synchronized block. If that synchronized block adds too much of a penalty, you CAN add random numbers or letters at the end. But that does not guarantee uniqueness, it only increases the likelihood. Run it enough times, and you are bound to find a collision. Since Gatling is for load testing, chances are you will eventually experience the collision. If that’s unacceptable, then I suggest you bite the bullet and guarantee uniqueness via the synchronized block solution.