BP Forums
Generating a Random Color - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19)
+---- Thread: Generating a Random Color (/showthread.php?tid=557)



Generating a Random Color - brandonio21 - 07-09-2012

Just thought that I would share this cool little snippet with you! A random color generator!

Pastebin Version: <!-- m --><a class="postlink" href="http://pastebin.com/CbvuhpG0">http://pastebin.com/CbvuhpG0</a><!-- m -->

[code2=java]//This method is intended to return a random color by generating random
// R,G, and B values (from 0 to 255) using Math.random()
public Color getRandomColor()
{
int randomR = (int) (Math.random() * 256);
int randomG = (int) (Math.random() * 256);
int randomB = (int) (Math.random() * 256);

return new Color(randomR, randomG, randomB); //Return the color
}[/code2]


Re: Generating a Random Color - Macatone - 09-01-2012

Thanks! Very helpful. Is it okay if I post versions of this for C# and Visual Basic .NET?


Re: Generating a Random Color - brandonio21 - 09-01-2012

Of course! Just post them in the proper forums!


Re: Generating a Random Color - Macatone - 09-01-2012

Okay, thanks!