# Setting limit of random colours

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

``````stroke(random(255),random(255),random(255));
fill(random(255),random(255),random(255));
``````

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?

1 Like

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

1 Like

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);
``````
1 Like

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.

2 Likes

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.

https://processing.org/reference/lerpColor_.html

``````color from = color(204, 102, 0);
color to = color(0, 102, 153);
void setup() {
frameRate(1);
}
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));
rect(0,0,10,10);
translate(10,0);
}
}
`````` 