Here you can find the source of randomFixedChars(int size, List
private static String randomFixedChars(int size, List<String> pool)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class Main { private static final ThreadLocalRandom random = ThreadLocalRandom .current(); private static String randomFixedChars(int size, List<String> pool) { int[] indexs = randomIndexs(size, pool.size()); StringBuffer buf = new StringBuffer(); for (int i = 0; i < indexs.length; i++) { buf.append(pool.get(indexs[i])); }//w ww.j av a 2 s . c o m return buf.toString(); } private static int[] randomIndexs(int count, int bound) { int[] indexs = new int[count]; for (int i = 0; i < count; i++) { indexs[i] = random.nextInt(bound); } return indexs; } }