Java ThreadLocalRandom randomFixedChars(int size, List pool)

Here you can find the source of randomFixedChars(int size, List pool)

Description

random Fixed Chars

License

Apache License

Declaration

private static String randomFixedChars(int size, List<String> pool) 

Method Source Code

//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;
    }
}

Related

  1. randomDelay()
  2. randomDouble(final double min, final double max)
  3. randomElement(Collection c, int n, boolean unique)
  4. randomEnum(Class clazz)
  5. randomFishType()
  6. randomIndexs(int count, int bound)
  7. randomInRange(int min, int max)
  8. randomInt()
  9. randomInt(int bound)