How can you avoid the same outcome twice when using random()?

So I created a random profile picture generator with a bunch of attributes, basically it creates a random number generator between 1 and 75, and decides which attribute to display based on which number is randomly chosen, some attributes have more numbers that will display them then others, creating a “rarity” system.

I am trying to figure out how I can avoid getting the same outcome more then once whenever I generate the images, how would anybody go about doing this? thankyou.

here’s an example of the code with 1 attribute instead of all 7 (code is the same for all of them)

PImage weather;

float bgweatherGenerator = random(1,23);
int newbgweatherGenerator = int(bgweatherGenerator); //convert float to int

   //Random Bacgkround Generator Outcomes

if(newBgGenerator > 0 & newBgGenerator < 16) {
background = loadImage(“1 dark blue.PNG”);

}

else if(newBgGenerator > 15 & newBgGenerator < 31) {
background = loadImage(“2 light blue.PNG”);
}

else if(newBgGenerator > 30 & newBgGenerator < 42) {
background = loadImage(“3 green.PNG”);
}

else if(newBgGenerator > 41 & newBgGenerator < 53) {
background = loadImage(“4 purple.PNG”);
}

else if(newBgGenerator > 52 & newBgGenerator < 62) {
background = loadImage(“5 pink.PNG”);
}

else if(newBgGenerator > 61 & newBgGenerator < 71) {
background = loadImage(“6 orange.PNG”);
}

else background = loadImage(“7 red.PNG”);

void draw() {
image(background,0,0);
background.resize(512,0);
image(background,0,0);
}

thankyou!

There is a shuffle-method So if you have an ArrayList with the numbers 1…75, take a copy, shuffle it and take the first m elements

2 Likes