HimanshuTayal
8 years agoCommunity Hero
I want a groovy simple code that generates Random number
I want a groovy simple code that generates Random number, and i don't want to add random number generator
Currently i am using:
import org.apache.commons.lang.RandomStringUtils
log.info getRandomNumber(8)
def getRandomNumber(int num)
{
String charset = (('1'..'9')).join()
def randValue = RandomStringUtils.random(num, charset)
while (randValue.size()!=num)
{
randValue = RandomStringUtils.random(num, charset)
}
return randValue
}Any alternate or better solution for this?