We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have an array where I am loading 10 images in it, as one can see below:
int maxImages = 10; // Total # of images
int imageIndex = int(random(10)); // Initial image to be displayed is the first
// Declaring an array of images.
PImage[] images = new PImage[maxImages];
// Loading the images into the array
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( "assets/images/image" + i + ".jpg" );
}
When certain conditions are met I am then using random() to generate a new value and save it in a new variable called imageIndex. As you can see below:
imageIndex = int(random(images.length));
After this is generated I am then calling the image with the new random number in the following way:
gameimages = loadImage( "assets/images/image" + imageIndex + ".jpg" );
The above implementation is working perfectly however random numbers are sometimes being generated more than once, I want them uniquely randomised from 1-10. Can anyone suggest me the best way to go about implementing this ?
Answers
maybe you just want to shuffle your 0,1,2... list?
http://forum.processing.org/two/discussion/626/cannot-find-anything-named-collections-arraylist/p1
What about this scheme w/ IntList, shuffle() & remove()? *-:)