We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to make a random color in processing. Online I found two solutions.
SOLUTION_A: color c=color(int(random(255)),int(random(255)),int(random(255)));
SOLUTION_B: color c=color(int(random(256)),int(random(256)),int(random(256)));
The difference being that SOLUTION_A uses random(255) and SOLUTION_B uses random(256)
What solution is correct?
I think SOLUTION_B correct but I'm not sure.
Answers
If you're removing the fractional part of the random()'s value, either via PApplet::int() or casting w/
(int)
or(color)
, the correct argument for a 0 to 255 range is 256. :-BA much shorter version for all possible 100% opaque colors:
(color) random(#000000);
:ar!@GoToLoop Thanks for the answer!!! It confirms what I thought. And thanks for the shortcut, it should come in handy.
@GoToLoop nice one, I wondered for a long time what a nice way would be instead of the
color(random(), random(), random())
.