how can i use random numbers in groovy?

前端 未结 5 1023
野性不改
野性不改 2020-12-13 17:49

I use this method:

def getRandomNumber(int num){
    Random random = new Random()
    return random.getRandomDigits(num)
}

when I call it I

5条回答
  •  渐次进展
    2020-12-13 18:30

    If you want to generate random numbers in range including '0' , use the following while 'max' is the maximum number in the range.

    Random rand = new Random()
    random_num = rand.nextInt(max+1)
    

提交回复
热议问题