Display random image(s) according to random number

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

1 Like

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

1 Like