# Display random image(s) according to random number

**URL:** <https://discourse.processing.org/t/display-random-image-s-according-to-random-number/14016>\
**Category:** Coding Questions\
**Created:** [September 16, 2019, 6:09pm UTC](https://discourse.processing.org/t/display-random-image-s-according-to-random-number/14016 "2019-09-16T18:09:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drastard](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/drastard/32/6452_2.png) [@Drastard](https://discourse.processing.org/u/Drastard)\
**Post date:** [September 16, 2019, 6:09pm UTC](https://discourse.processing.org/t/display-random-image-s-according-to-random-number/14016/1 "2019-09-16T18:09:25Z")

</div>

It’s been several years since I scraped through any kind of coding but I’ve come back to Processing as I finally have a problem to solve rather than completing something a teacher set!

I would like to display a series of images according to a randomly generated number.

If, for example, the number is 2649, the output will be 2 x Image\_A, 6 x Image\_B, 4 x Image\_C and 9 x Image\_D. Images should be non-overlapping. This is for a classroom resource. The images will be base 10 blocks (for anyone interested).

Can anyone suggest a suitable way of doing this / point me in the right direction.

Thanks in advance

---

<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:** [September 16, 2019, 8:51pm UTC](https://discourse.processing.org/t/display-random-image-s-according-to-random-number/14016/2 "2019-09-16T20:51:51Z")

</div>

Try to break down this into steps.

Make a random number int index = int(random(maxNumber));

Then convert into string s1

Then use charAt to get char

char index0char= s1.charAt(0);  
char index1char=s1.charAt(1);  
char index2char=…

Convert char back to number

int index0=…

Use as index for the different image arrays
