Create random integers in a specific range

For example you would like to create 10 pseudo random numbers between 0 and 10.


In Java there is the nextInt(int i) Method which:

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator’s sequence.

JavaDoc.

import java.util.Random
Random rand = new Random()
int max = 10
def randomIntegerList = []
(1..10).each {
randomIntegerList << rand.nextInt(max+1)
}


[0, 10, 5, 4, 4, 10, 5, 0, 8, 2]