Forum Discussion
Finan
14 years agoFrequent Contributor
Hi,
If you want to create a random number with 10 digits, use the following groovy script:
If you want to limit the value of a digit on a specific spot (for instance, the first digit is always a zero) you can use nr.lenght() to assert the digit-position:
Of course you still need to set the value of nr to the correct parameter in your XML...
If you want to create a random number with 10 digits, use the following groovy script:
int a = 9
nr = ""
for(i = 0; i < 10; i++)
{
random = new Random()
randomInteger= random.nextInt(a)
nr = nr + randomInteger
}
log.info nr
If you want to limit the value of a digit on a specific spot (for instance, the first digit is always a zero) you can use nr.lenght() to assert the digit-position:
int a = 9
nr = ""
for(i = 0; i < 10; i++)
{
if(nr.length() < 1)
{
nr = nr + "0"
}
else
{
random = new Random()
randomInteger= random.nextInt(a)
nr = nr + randomInteger
}
}
log.info nr
Of course you still need to set the value of nr to the correct parameter in your XML...