title: Is there a way to have randomized string values in an array only be called once while using a for loop?
body: <p>I want to make a program where you enter input in a for loop and after the iterations, a randomized string value from an array gets placed with it in the output message at the end.
  I do not want the string values to repeat, I want each value to only be produced once. How can I go about doing that? (the int values and the string values in the two arrays need to stay matched as well, so apples should always lead to liking he number 1, bananas the number 2 etc)</p>
  <p>I want the output to be like:</p>
  <p><strong>Alex likes mangos and the number 3</strong></p>
  <p><strong>John likes apples and the number 1</strong></p>
  <p><strong>Jane likes bananas and the number 2</strong></p>
  <p>instead of:</p>
  <p><strong>Alex likes mangos and the number 3</strong></p>
  <p><strong>John likes mangos and the number 3</strong></p>
  <p><strong>Jane likes apples and the number 1</strong></p>
  <pre><code>package example;
  import javax.swing.JOptionPane;
  import java.util.Random;
  public class Example {
  
      public static void main(String[] args) {
          
          StringBuilder generator = new StringBuilder();
          
          for (int a=1; a&lt;4; a++){
              
              String name = JOptionPane.showInputDialog(null, &quot;Enter person &quot; + a + &quot;'s name&quot;);
              
              Random random = new Random();
              String [] fruit = {&quot;apples&quot;, &quot;bananas&quot;, &quot;mangos&quot;};
              int [] number = {1, 2, 3};
              int randomIndex = random.nextInt(fruit.length);
              
              generator.append(name).append(&quot; likes &quot;).append(fruit[randomIndex]).append(&quot; and the number &quot;).append(number[randomIndex]).append(&quot;\n&quot;);     
          }
          JOptionPane.showMessageDialog(null, generator);
      }
      
  }
  </code></pre>