Here you can find the source of getRandomColors(final int size, final List
Parameter | Description |
---|---|
size | the size |
colors | the list of color |
public static List<String> getRandomColors(final int size, final List<String> colors)
//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); } }