Reputation: 151
I have a requirement to generate a Random mobile number and input it in my subsequent request. During load test when running using multiple users ( ~1k users), how should I ensure the uniqueness of it across all my users?
I am using a groovy script for this task that generates a mobile number randomly.
(int)Math.floor(Math.random() * (9000000000 - 9000020000)) + 9000020000
I know that I can pre-generate the random mobile numbers and send as parameters. But I don't want to use this approach of static/parameterized data.
Upvotes: 0
Views: 3671
Reputation: 617
If there is a formatting requirement on the mobile number you could prefix a timestamp and limit the output to the remaining number of digits like so:
Note: Mddmmsss will add 8 random digits to the prefix 077 (total of 11 digits like a standard UK phone number)
077${__time(Mddmmsss,)}
output exmaple:
07792203003
Upvotes: 1
Reputation: 168147
You cannot guarantee the "uniqueness" if you're talking about random.
You could do something like:
Example code:
def timestamp = System.nanoTime()
def currentUser = ctx.getThreadNum()
def iteration = vars.getIteration()
def randomValue = timestamp as String + currentUser + iteration
vars.put('randomValue', randomValue)
More information on the aforementioned JMeter API shorthands: Top 8 JMeter Java Classes You Should Be Using with Groovy
Upvotes: 2
Reputation: 1841
You could use Java faker to generate the random number.
import com.github.javafaker.service.FakeValuesService
import com.github.javafaker.service.RandomService
FakeValuesService fakeValuesService
fakeValuesService = new FakeValuesService(new Locale("en-AU"), new RandomService());
String prefixMobile = "04"
String mobileNumber = fakeValuesService.regexify(String.format("%s\\d{8}", prefixMobile))
vars.put("mobileNumber",mobileNumber)
You will have to download the jar file, place the jar inside JMETER_HOME/bin folder and restart the JMeter to ensure the jar is available for your test.
Upvotes: -1