Tags
Generate Random String with Groovy
Groovy makes really easy to generate random string sequence, here is the code snippet for random string generator:
def length = 16 // the size of the random string
def pool = [‘a‘..’z‘, ‘A‘..’Z‘, 0..9, ‘-‘].flatten() // generating pool
Random random = new Random(System.currentTimeMillis())
// the loop should be from 0 to length – 1, then the char length would be length
def randomChars = (0..length –1).collect { pool[random.nextInt(pool.size())] }
def randomString = randomChars.join()