# Setting limit of random colours

**URL:** <https://discourse.processing.org/t/setting-limit-of-random-colours/6051>\
**Category:** Coding Questions\
**Created:** [November 28, 2018, 9:50pm UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051 "2018-11-28T21:50:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CowPieForever](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@CowPieForever](https://discourse.processing.org/u/CowPieForever)\
**Post date:** [November 28, 2018, 9:50pm UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051/1 "2018-11-28T21:50:53Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 28, 2018, 10:29pm UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051/2 "2018-11-28T22:29:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CowPieForever](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@CowPieForever](https://discourse.processing.org/u/CowPieForever)\
**Post date:** [November 28, 2018, 10:54pm UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051/3 "2018-11-28T22:54:10Z")

</div>

thank you I didn’t realize it was that easy

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [November 29, 2018, 12:14am UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051/4 "2018-11-29T00:14:20Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![djokjula](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/djokjula/32/2544_2.png) [@djokjula](https://discourse.processing.org/u/djokjula)\
**Post date:** [November 29, 2018, 12:20am UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051/5 "2018-11-29T00:20:17Z")

</div>

A quick way to figure these things out is to use the [references](https://processing.org/reference/), 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.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 6, 2018, 8:21pm UTC](https://discourse.processing.org/t/setting-limit-of-random-colours/6051/6 "2018-12-06T20:21:07Z")

</div>

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](https://processing.org/reference/lerpColor_.html)

```auto
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);
  }
}

```

![39%20PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/98f5eeea05b3ab45f064e8377298696e56280ecd.png)
