有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何生成半随机颜色列表?

我想查看随机生成的颜色列表,并检查它们是否彼此不同。与colour1 == colour2不同,但要确保生成的颜色不太相似

我的意思是使用以下代码(或类似代码)生成颜色列表:

Random randomGenerator = new Random();
ArrayList<Color> colours = new ArrayList<Color>();
while(true) {
    int red = randomGenerator.nextInt(255);
    int green = randomGenerator.nextInt(255);
    int blue = randomGenerator.nextInt(255);
    Color randomColour = new Color(red,green,blue);
    if(!colours.contains(randomColour)) {
        colours.add(randomColour);
    }
    if(colours.size() >= 100) {
        break;
    }
}

共 (0) 个答案