title: How can I limit each number of occuring only once, so my secret code won't have double numbers
body: <p>The code is supposed to return a secret code in form of colors, which it did do before the if conditions were added. The problem that occures to me, if I don't try to limit the numbers to occuring only once is as follows</p>
  <p>Removing the if conditions from the cases makes the code &quot;work&quot; again but it also results in the numbers being repeated and sometimes leads to not even printing a number. Does anybody have an idea how to stop numbers from reoccuring?</p>
  <pre><code>int[] secretcode = new int[4];  
  String[] farbcode = new String[4];  
  
  public rndmcode() { // array &quot;secretcode&quot; wird definiert
      Arrays.fill(farbcode, &quot;&quot;);
      for (int i = 0; i &lt; 4 &amp;&amp; farbcode.length &lt; 4; i++){                                                      
          //Schleife um eine Randomziffer von 1-6 zu erstellen und
          //https://trainyourprogrammer.de/java-203-programmierung-von-mastermind.html    //bis zur 4ten Stelle vom Array, da der Code 4 Zahlen bracht
          Random zufallszahl = new Random();                                      
          int rndnumber = zufallszahl.nextInt(7); //Die Zahlen 1-6 sind meine Farben, die vorrerst nur Zahlen sind
          
          switch(rndnumber) {
          case 1:
              if(Arrays.asList(farbcode).contains(&quot;Blau&quot;)){
          
              break;
              }
              else
                  {farbcode[i] += &quot;Blau&quot;;
              break;}
          case 2:
              if(Arrays.asList(farbcode).contains(&quot;Rot&quot;)) {
                  break;
              
              }
          
              else
                  {farbcode[i] += &quot;Rot&quot;;
              break;}
          case 3: 
              if(Arrays.asList(farbcode).contains(&quot;Gelb&quot;)){
                  break;
                  }
              else{
                  farbcode[i] += &quot;Gelb&quot;;
              
              break;}
          case 4:
              if(Arrays.asList(farbcode).contains(&quot;Grün&quot;)){
                  break;
                  }
              else{
                  farbcode[i] += &quot;Grün&quot;;
              
              break;
              }
          case 5:
              if(Arrays.asList(farbcode).contains(&quot;Lila&quot;)){
                  break;
                  }
              else {farbcode[i] += &quot;Lila&quot;;
              break;}
          
          case 6:
              if(Arrays.asList(farbcode).contains(&quot;Orange&quot;)){
                  break;
                  }
              else {
              farbcode[i] += &quot;Orange&quot;;
              break;
              }
          default:
          }
      }
  }
  public String stringo() {
  
      String s = &quot;[&quot;;
      for (String element:farbcode) {
          s+=element;
          s+=&quot;, &quot;;
      }
      s+= &quot;]&quot;;
      return s;
  }
  </code></pre>