# Help with array (upper bound)

**URL:** https://discourse.processing.org/t/help-with-array-upper-bound/41208
**Category:** Coding Questions
**Created:** [March 9, 2023, 8:16am UTC](https://discourse.processing.org/t/help-with-array-upper-bound/41208 "2023-03-09T08:16:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kristianjones](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@kristianjones](https://discourse.processing.org/u/kristianjones)
#### Post date: [March 9, 2023, 8:16am UTC](https://discourse.processing.org/t/help-with-array-upper-bound/41208/1 "2023-03-09T08:16:46Z")

</div>

Hi there. I have a question about a sketch i’m working on. I have it working the way I want it to, but, I want to change the amount of images that are displayed randomly from the array. It seems to currently display around 5, and i’m not sure where this is being stipulated in the code and where to change it. I’d like to set the display of the images to 10 random ones from the array. Any help / guidance would be greatly appreciated. Working code below. Thank you

* * *

PImage images;

void setup() {  
frameRate(1);  
size(800, 800);

images = new PImage[32]; // Create an array of 32 images  
for (int i = 0; i \< images.length; i++) {  
images[i] = loadImage( i + “.png”); // Load each image from a file  
}  
}

void draw() {  
background(255);  
blendMode(MULTIPLY);  
shuffleArray(images); // Shuffle the array of images  
for (int i = 0; i \< images.length; i++) {  
image(images[i], i \* random(width), random(height)); // Display each image in a row  
}  
}

void shuffleArray(PImage array) {  
for (int i = array.length - 1; i \> 0; i–) {  
int j = (int) random(i + 1); // Generate a random index  
// Swap the elements at indices i and j  
PImage temp = array[i];  
array[i] = array[j];  
array[j] = temp;  
}  
}

void keyPressed() {  
if (key == ‘s’) {  
println(“Saving…”);  
saveFrame(“screen-####.jpg”);  
println(“Done saving.”);  
noLoop();  
}  
}

---

<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: [March 9, 2023, 8:31am UTC](https://discourse.processing.org/t/help-with-array-upper-bound/41208/2 "2023-03-09T08:31:51Z")

</div>

> [@kristianjones](#):
>
> `image(images[i], i * random(width),...`

This is in the draw() function.

Please try to delete `i *`.

---

<div class="post-metadata">

### Author: ![kristianjones](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@kristianjones](https://discourse.processing.org/u/kristianjones)
#### Post date: [March 9, 2023, 8:48am UTC](https://discourse.processing.org/t/help-with-array-upper-bound/41208/3 "2023-03-09T08:48:42Z")

</div>

Hi there, thank you for the reply! Thank worked to a point, I removed the i \* and now it displays a lot more! Is there a way I can control the amount of images displayed? So I can stipulate a value ?

Thank you!

---

<div class="post-metadata">

### Author: ![kristianjones](https://avatars.discourse-cdn.com/v4/letter/k/bbe5ce/32.png) [@kristianjones](https://discourse.processing.org/u/kristianjones)
#### Post date: [March 9, 2023, 8:57am UTC](https://discourse.processing.org/t/help-with-array-upper-bound/41208/4 "2023-03-09T08:57:21Z")

</div>

found my answer! for (int i = 0; i \< 3; i++) {  
I just had to change the value here in the loop. Thank you for your help on this! Much appreciated!

---

<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: [March 9, 2023, 9:39am UTC](https://discourse.processing.org/t/help-with-array-upper-bound/41208/5 "2023-03-09T09:39:07Z")

</div>

Good work!

- 3 is the upper bound.

And welcome to the forum!

Great to see you here!
