int i = (int)random(5);
PImage img = loadImage("filename_" + i + ".jpg");
if you have image files called filename_0.jpg, filename_1.jpg ... filename_4.jpg then it'll load the relevant one. ("filename_" can be anything, including nothing)
(if you have more than 10 images then it's best to zero-pad the names (filename_00.jpg) and format the variable accordingly using nf())
Answers
Java demands that all variable names be known at compile time.
You may try a HashMap<Integer,PImage> out though:
https://Processing.org/reference/HashMap.html
if you have image files called filename_0.jpg, filename_1.jpg ... filename_4.jpg then it'll load the relevant one. ("filename_" can be anything, including nothing)
(if you have more than 10 images then it's best to zero-pad the names (filename_00.jpg) and format the variable accordingly using nf())
ayy chris wassup m8