Java Random String getRandomColors(final int size, final List colors)

Here you can find the source of getRandomColors(final int size, final List colors)

Description

Get RANDOM colors

License

Apache License

Parameter

Parameter Description
size the size
colors the list of color

Return

a list of string

Declaration

public static List<String> getRandomColors(final int size, final List<String> colors) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    private static final Random RANDOM = new Random();

    /**/*from www.j av a 2 s.  c  om*/
     * Get RANDOM colors
     *
     * @param size   the size
     * @param colors the list of color
     * @return a list of string
     */
    public static List<String> getRandomColors(final int size, final List<String> colors) {
        final Set<String> res = new HashSet<>();
        while (res.size() != size) {
            final String color = colors.get(RANDOM.nextInt(colors.size()));
            res.add(color);
        }
        return new ArrayList<>(res);
    }
}

Related

  1. genRandomString()
  2. genRandomString(final int length)
  3. genRandomString(int count)
  4. getDefaultRandomName(String namePrefix)
  5. getRandomAString(int min, int max)
  6. getRandomElementOrCompound(String equation)
  7. getRandomFromTier(int tier, String lvlRange)
  8. getRandomNumberString(int length)
  9. getRandomNumberString(int maxValue, int strLen)