title: How to create an array of random security codes in Java?
body: <p>I am trying to write a program that would ask the user how many security codes he wants to generate, then it would output as many codes as he requested in an array.</p>
  <p>The security code should be 7 characters long and have the following format: NNNNLLL, where N is a random number and L is a random upper case letter.</p>
  <p>The method should create security codes with the above format by randomly selecting the characters, i.e. numbers and letters.</p>
  <p>I am expecting the program to output something like this if a user selects to generate 4 codes:</p>
  <p>“2394QAB”
  “2821TSZ”
  “7173AAY”
  “2236WQA”</p>
  <p>I can only use the methods for this code learned in my course and I cannot use other libraries like regex, that is why I am trying it like this.</p>
  <p>This is the code I have done so far:</p>
  <pre><code>import java.util.Random;
  public class ItemChecker{
  
      private StringBuffer strBuff;
      private String[] codes;
      private String CodeLetters, CodeNumbers;
      private int[] RandomNums;
  
      public ItemChecker(){
              strBuff=new StringBuffer();
      }
  
      public String[] getCodes(int[] amount){
          codes=new String[amount.length];
          for(int i=0;i&lt;amount.length;i++)
              {
              CodeLetters=&quot;&quot;;
              strBuff=new StringBuffer();
                  for(int j=0;j&lt;4;j++)
                      {
                          Random RandomNumber=new Random();
                          int randomIndex=RandomNumber.nextInt(RandomNums.length);
  
                          CodeNumbers.append(RandomNumber[randomIndex]);
                      }
                  for(int j=0;j&lt;3;j++)
                      {
                          Random RandomLetter=new Random();
                          char c =(char)(RandomLetter.nextInt(26)+'a');
                          CodeLetters+=c;
                      }
              codes[i]=CodeNumbers+CodeLetters;
          }
      }
  
  
  }
  </code></pre>
  <p>My intention is to create 4 random digits and 3 random letters and add them together in a string to make the code. However, the code doesn't generate the random codes and I have no clue how to proceed from here.</p>