Setting limit of random colours


So I have written that, when drawing a shape, the stroke and fill are random colours:


So if I wanted to set the colours to be random between certain parameters, for example, keep it brighter than, say, 150, but not brighter than 220. How would I write that?


You can use 2 parameters in the random(); functions, so random(150, 220);;


thank you I didn’t realize it was that easy


Even if you couldn’t supply 2 parameters, you could do something like this:

var minimum = 150;
var maximum = 220;
var value = minimum + random(maximum - minimum);


A quick way to figure these things out is to use the references, it is a really good source.

For your example, you can search (ctrl + f) for random, and you will find a lot of usefull stuff.


Another option is to choose a random point on a color spectrum using lerpColor() and passing it two colors and a random value between 0-1.

color from = color(204, 102, 0);
color to = color(0, 102, 153);
void setup() {
void draw() {
  // random background in color range
  color randc = lerpColor(from, to, random(1));
  background (randc);
  // draw color bar
  for(int i=0; i<10; i++){
    fill(lerpColor(from, to, i/10.0));


Hue with specific colors