# Creating a list of random colors that does not update

**URL:** <https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041>\
**Category:** Coding Questions\
**Created:** [January 13, 2021, 11:13pm UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041 "2021-01-13T23:13:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackeddielove](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jackeddielove](https://discourse.processing.org/u/jackeddielove)\
**Post date:** [January 13, 2021, 11:13pm UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/1 "2021-01-13T23:13:52Z")

</div>

I would like to create an array of 100 randomly chosen colors that I can pick from throughout my “draw” code.

If I use

color[] colors = new color[100];  
for (int i = 0; i\<100; i++) {  
colors[i]= color(random(255), random(255), random(255));  
}

inside draw, the list is updated over and over (which I don’t want). If I use the same code in setup, I can’t access the variable “colors” in draw. If I use the same code in between setup and draw, I get an error “expecting EOF, found ‘for’”.

An example of how I intend to use such an array:

for (int j=0; j\<10; j++) {  
fill(colors[j]);  
rect(j\*100, 100, 100, 100);  
}

I realize I only use 10 colors in this example, but I really do want access to 100 random colors.

---

<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:** [January 13, 2021, 11:28pm UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/2 "2021-01-13T23:28:45Z")

</div>

> [@jackeddielove](#):
>
> inside draw, the list is updated over and over

Yes. That’s what draw() does

Make this in setup not in draw()

---

<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:** [January 13, 2021, 11:29pm UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/3 "2021-01-13T23:29:05Z")

</div>

> [@jackeddielove](#):
>
> color colors = new color[100];

This belongs before setup ()

---

<div class="post-metadata">

**Author:** ![jackeddielove](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jackeddielove](https://discourse.processing.org/u/jackeddielove)\
**Post date:** [January 13, 2021, 11:45pm UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/4 "2021-01-13T23:45:35Z")

</div>

Beautiful. Thank you kindly.

---

<div class="post-metadata">

**Author:** ![jackeddielove](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jackeddielove](https://discourse.processing.org/u/jackeddielove)\
**Post date:** [January 14, 2021, 12:07am UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/5 "2021-01-14T00:07:03Z")

</div>

I’m new to the forum. Is there a way to thank you besides just saying thank you?

---

<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:** [January 14, 2021, 12:14am UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/6 "2021-01-14T00:14:44Z")

</div>

That’s pretty much it.

😉

You are welcome!

Hey, and welcome to the forum!

Great to have you here!

---

<div class="post-metadata">

**Author:** ![Prxt.3k](https://avatars.discourse-cdn.com/v4/letter/p/9e8a1a/32.png) [@Prxt.3k](https://discourse.processing.org/u/Prxt.3k)\
**Post date:** [January 14, 2021, 5:20am UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/7 "2021-01-14T05:20:36Z")

</div>

Hey, I saw a lot of your replies I am a beginner and you seem to enjoy helping new people. I would appreciate it if you could help me. I just posted a question, is there a way I can personally talk to you regarding my issue or visit here: [\*URGENT\* Assistance with Drawing Program](https://discourse.processing.org/t/urgent-assistance-with-drawing-program/27046)

THANK YOU,

---

<div class="post-metadata">

**Author:** ![jackeddielove](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jackeddielove](https://discourse.processing.org/u/jackeddielove)\
**Post date:** [January 14, 2021, 3:56pm UTC](https://discourse.processing.org/t/creating-a-list-of-random-colors-that-does-not-update/27041/8 "2021-01-14T15:56:12Z")

</div>

Thanks, great to be here! I started teaching myself Processing a few months ago and am fully loving it.
