# 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:** 1
**Showing post:** 6

<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)

---

_[View the full topic](https://discourse.processing.org/t/setting-limit-of-random-colours/6051)._
