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

**URL:** <https://discourse.processing.org/t/how-can-you-avoid-the-same-outcome-twice-when-using-random/32760>\
**Category:** Coding Questions\
**Created:** [October 11, 2021, 8:10pm UTC](https://discourse.processing.org/t/how-can-you-avoid-the-same-outcome-twice-when-using-random/32760 "2021-10-11T20:10:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![colehodl](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@colehodl](https://discourse.processing.org/u/colehodl)\
**Post date:** [October 11, 2021, 8:10pm UTC](https://discourse.processing.org/t/how-can-you-avoid-the-same-outcome-twice-when-using-random/32760/1 "2021-10-11T20:10:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Aardappel](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Aardappel](https://discourse.processing.org/u/Aardappel)\
**Post date:** [October 11, 2021, 9:27pm UTC](https://discourse.processing.org/t/how-can-you-avoid-the-same-outcome-twice-when-using-random/32760/2 "2021-10-11T21:27:12Z")

</div>

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
