android生成随机唯一颜色代码[关闭](android generate randomly unique color code [closed])
我想生成随机,独特的颜色代码。 有算法吗?
I want to generate random,unique color code. Is there any algorithm ?
原文:https://stackoverflow.com/questions/4733326
更新时间:2020-02-14 03:06
最满意答案
Random color = new Random();
Color randomColor = new Color(color.nextInt(256),color.nextInt(256),color.nextInt(256));
迂腐地说,不确定是随意的;)
Random color = new Random();
Color randomColor = new Color(color.nextInt(256),color.nextInt(256),color.nextInt(256));
Ofcouse pedantically speaking, not assured to be random ;)
2011-01-19
相关问答
Random rnd = new Random();
paint.setARGB(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
要么 Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
view.setBackgroundColor(color);
...
您可以将随机颜色的RGB值与恒定颜色的RGB值进行平均: (Java中的例子) public Color generateRandomColor(Color mix) {
Random random = new Random();
int red = random.nextInt(256);
int green = random.nextInt(256);
int blue = random.nextInt(256);
// mix the color
...
获取从0到255的随机数,然后将其转换为十六进制: function random_color_part() {
return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT);
}
function random_color() {
return random_color_part() . random_color_part() . random_color_part();
}
echo random_co
...
你有 float x = (20-counter)/10;
给定counter是一个int,(20-counter)/ 10只能是0,1或2.你必须添加一个类型转换: float x = (float)(20-counter) / 10;
或者更容易 float x = (20f - counter) / 10f;
You have float x = (20-counter)/10;
Given counter is an int, (20-counter)/10 can only be
...
setArgb的第一个参数是透明度。 您应该始终将其设置为255。 First param at setArgb is transparency. You should always set it to 255.
你需要将“色彩空间”想象成一个三维空间,然后看看你所选择的空间之间的距离。 即r1,g1,b1与r2,g2,b2之间的距离为sqrt((r1-r2)^2+(g1-g2)^2+(b1-b2)^2) 然后,您可以检查事情的密切程度,并定义一个阈值。 一个更容易的方法,虽然将只是定义一个可接受的颜色“网格”间隔足够远的方式看起来不同。 即r = random.nextInt(4)*32, g = random.nextInt(4)*32, b = random.nextInt(4)*32 现在,您只需检
...
一个更好的选择是通常生成随机色调,并使用HSL或HSV颜色(使用该色调)将色调转换为RGB颜色。 通过使用随机的“色调”而不是随机的颜色,你会得到更多的颜色变化。 如果你需要更多的变化,你也可以随机化其他组件(饱和度/值等)。 有关使用HSV / HSL处理颜色的详细信息,请参阅维基百科 ,包括如何将HSV转换为RGB 。 A better option is to typically generate a random hue, and the convert the hue to an RGB
...
如果要使用标准控制台颜色,可以混合使用ConsoleColor Enumeration和Enum.GetNames()以获得随机颜色。 然后,您可以使用Console.ForegroundColor和/或Console.BackgroundColor来更改控制台的颜色。 // Store these as static variables; they will never be changing
String[] colorNames = ConsoleColor.GetNames(typeof(
...
你可以洗牌数组并使用array的.pop()方法来获得你的唯一性。 :) $(function () {
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick
...
Random color = new Random();
Color randomColor = new Color(color.nextInt(256),color.nextInt(256),color.nextInt(256));
迂腐地说,不确定是随意的;) Random color = new Random();
Color randomColor = new Color(color.nextInt(256),color.nextInt(256),color.nextInt(256)
...