Skip to end of metadata
Go to start of metadata

The random variable in JMeter is not random enough, even with 100 users 2 - 4 duplicate phone numbers are created within a range of 30.000.000 numbers. For this reason a JavaBeans script is written to calculate this number. Suppose two threads do still get the same number, the number of that thread is subtracted from the random value to create uniqueness. 

import java.text.SimpleDateFormat;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;

int myThreadNum = 0;
int randomUser = 0;
int randomBuddy = 0;

Random randomvar = new Random();

DecimalFormat myDecimalFormat = new DecimalFormat("########");  // required to prevent thousand separators

myThreadNum = ${__threadNum}; // just to show the thread number in debug
vars.put("myThreadNum",myDecimalFormat.format(myThreadNum));

// Random user generator
// Random User  is between 10000000 - 39999999
// Random Buddy is between 40000000 - 59999999
randomUser = 10000000 + randomvar.nextInt(29999999) - myThreadNum;
vars.put("User",myDecimalFormat.format(randomUser));

randomBuddy =  40000000 + randomvar.nextInt(19999999) - myThreadNum;
vars.put("Buddy",myDecimalFormat.format(randomBuddy));
// the buddy number that was used during creation of the buddy is stored and used to link the user to that specific buddy

  • No labels