Randomizing value of timestamp


I doing multiple requests which take timestamp (generated with current time) as a parameter. I want to have each instance of this variable called to have different value (or value of time in milliseconds) when it was called, without using that many number of variables.

Currently I am doing it as below:

val startTime = System.currentTimeMillis().toString
val endTime = System.currentTimeMillis().toString

I tried ThreadLocalRandom as below but its generating time for a date well in past. How this can be achieved.

val startTime = ThreadLocalRandom.current().nextLong(System.currentTimeMillis()).toString

val endTime = ThreadLocalRandom.current().nextLong(System.currentTimeMillis()).toString


Read https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadLocalRandom.html#nextLong(long) javadoc, so you’ll find out you want the method just closed to it.