# If I have a grid of 50x50 rectangles how can I randomly place an image in only a few of them?

**URL:** https://discourse.processing.org/t/if-i-have-a-grid-of-50x50-rectangles-how-can-i-randomly-place-an-image-in-only-a-few-of-them/39326
**Category:** Coding Questions
**Created:** [October 17, 2022, 9:37pm UTC](https://discourse.processing.org/t/if-i-have-a-grid-of-50x50-rectangles-how-can-i-randomly-place-an-image-in-only-a-few-of-them/39326 "2022-10-17T21:37:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ExplodingWhale](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@ExplodingWhale](https://discourse.processing.org/u/ExplodingWhale)
#### Post date: [October 17, 2022, 9:37pm UTC](https://discourse.processing.org/t/if-i-have-a-grid-of-50x50-rectangles-how-can-i-randomly-place-an-image-in-only-a-few-of-them/39326/1 "2022-10-17T21:37:28Z")

</div>

I could use a for loop for the amount of images but how do i make the random function match the exact location of the rectangles?

---

<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: [October 17, 2022, 9:44pm UTC](https://discourse.processing.org/t/if-i-have-a-grid-of-50x50-rectangles-how-can-i-randomly-place-an-image-in-only-a-few-of-them/39326/2 "2022-10-17T21:44:21Z")

</div>

It would be good to see some code of yours

In theory you want to have an array (2D or 1D) to stire the information whether the cell has an image or not

```auto
If (grid [x][y] == 1 ) {
   image(gridImage [x][y] , x*10,y*10);
}

```
