# How to assign random colors to multiple objects

**URL:** https://discourse.processing.org/t/how-to-assign-random-colors-to-multiple-objects/31919
**Category:** Coding Questions
**Created:** [August 25, 2021, 12:27pm UTC](https://discourse.processing.org/t/how-to-assign-random-colors-to-multiple-objects/31919 "2021-08-25T12:27:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jimjimmer](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jimjimmer](https://discourse.processing.org/u/jimjimmer)
#### Post date: [August 25, 2021, 12:27pm UTC](https://discourse.processing.org/t/how-to-assign-random-colors-to-multiple-objects/31919/1 "2021-08-25T12:27:18Z")

</div>

I’m trying to write a code which draws a circle at each of a series of coordinates given from a csv file.  
I want to give each circle a random color but my code at present gives the same color to all the circles.  
How can I achieve what I want?!  
thankyou  
//  
// takes xy coordinates of and draws a circle at each point

```auto
Table table;

void setup() {

  table = loadTable("xyloc.csv", "header");
  size(1400, 600);

  for (TableRow row : table.rows()) {

    int x = row.getInt("x");
    int y = row.getInt("y");
    fill(random(255), random(255), random(255));
    ellipse(x/5, y/5, 2, 2);
  }
}

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [August 25, 2021, 12:55pm UTC](https://discourse.processing.org/t/how-to-assign-random-colors-to-multiple-objects/31919/2 "2021-08-25T12:55:19Z")

</div>

Hi @jimjimmer,

Welcome to the forum! 😉

> [@jimjimmer](#):
>
> Firstly I’m really sorry I can’t figure out how to format my code please let me know and forgive me…

No problem, just hit the `</>` button when editing a message or use triple backticks ``` around your code like this: ``` code ``` → `code`

Your code should work since the `random()` function is giving a random result each time its called (by definition). Therefore your ellipses should be filled with a random color.

Check this code (similar to yours):

```processing
void setup() {
  size(500, 500);
  background(255);
}

void draw() {
  float rx = random(width);
  float ry = random(height);
  
  fill(random(255), random(255), random(255));
  circle(rx, ry, 50);
}

```

![test](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d3f6213d91b8056ea7b76a6a8365388980f9481a.png)

---

<div class="post-metadata">

### Author: ![jimjimmer](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jimjimmer](https://discourse.processing.org/u/jimjimmer)
#### Post date: [August 25, 2021, 1:02pm UTC](https://discourse.processing.org/t/how-to-assign-random-colors-to-multiple-objects/31919/3 "2021-08-25T13:02:16Z")

</div>

Ha what a ditz yes it does work doesn’t it ! My circles were too small on the screen and I couldn’t see the variation! Thanks ever so much I’m sure I will be back soon!

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [August 25, 2021, 1:33pm UTC](https://discourse.processing.org/t/how-to-assign-random-colors-to-multiple-objects/31919/4 "2021-08-25T13:33:38Z")

</div>

That’s it, 2 pixels large is quite small! 😉

Have fun programming 😋
