# for-Loop w/ Array of random RGB values

**URL:** <https://discourse.processing.org/t/for-loop-w-array-of-random-rgb-values/11084>\
**Category:** Beginners\
**Created:** [May 9, 2019, 7:44pm UTC](https://discourse.processing.org/t/for-loop-w-array-of-random-rgb-values/11084 "2019-05-09T19:44:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![r8th](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/r8th/32/5105_2.png) [@r8th](https://discourse.processing.org/u/r8th)\
**Post date:** [May 9, 2019, 7:44pm UTC](https://discourse.processing.org/t/for-loop-w-array-of-random-rgb-values/11084/1 "2019-05-09T19:44:40Z")

</div>

Hi! I’m using Casey and Ben’s Getting Stared with Processing book. Example 11-8, pp 155-156, shows how to fill an ARRAY w RANDOM values using a FOR loop. The RANDOM values are passed to STROKE values. The example below is in Gray.

I thought it would be very straight forward to change the STROKE values from random Gray, to random RGB…I was wrong–it’s IMPOSSIBLE!!! haha. 🙃 Could someone please help with advice on changing stroke values to random RGB.

Thanks!

```auto
float[] rainbow;

void setup() {
  colorMode(RGB);
  size(600, 600);
  rainbow = new float[width];
  for(int i = 0; i < rainbow.length; i++) {
    rainbow[i] = random(0, 255);
  }
}

void draw() {
  for(int i=0; i < rainbow.length; i++ ) {
    stroke(rainbow[i]);
    line(i, 0, i, height);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 9, 2019, 8:28pm UTC](https://discourse.processing.org/t/for-loop-w-array-of-random-rgb-values/11084/2 "2019-05-09T20:28:19Z")

</div>

```auto

color[] rainbow;

void setup() {
  // colorMode(RGB);
  size(600, 600);
  rainbow = new color[width];
  for (int i = 0; i < rainbow.length; i++) {
    rainbow[i] = color(random(0, 255), random(0, 255), random(0, 255));
  }
}

void draw() {
  for (int i=0; i < rainbow.length; i++ ) {
    stroke(rainbow[i]);
    line(i, 0, 
      i, height);
  }
}

```

---

<div class="post-metadata">

**Author:** ![r8th](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/r8th/32/5105_2.png) [@r8th](https://discourse.processing.org/u/r8th)\
**Post date:** [May 10, 2019, 5:18am UTC](https://discourse.processing.org/t/for-loop-w-array-of-random-rgb-values/11084/3 "2019-05-10T05:18:07Z")

</div>

oh my gosh… THANK YOU!!!
