title: how to code a specefic random number scheme?
body: <p>I am learning Java. I just want to write a method that generates random numbers that comes in a specific set, like a bank credit card  " xxxx - xxxx - xxxx - xxxx ". Each chunk needs to be exactly 4 digit long. anybody has any solution?</p>
  
  <pre><code>public class Main {
  </code></pre>
  
  <p>public static User accountHolders[] = new User[100];
     public static int index = 0;</p>
  
  <pre><code>public static void main(String[] args) {
  
      Scanner input = new Scanner(System.in);
  
      while (true) {
  
          System.out.println("\t-----\tWelcome to The Bank portal\t-----");
          System.out.println("\nPlease enter the number of your required action");
          System.out.println("\n1) Make a Deposit");
          System.out.println("2) Get balance");
          System.out.println("3) Register new account");
          System.out.println("0) Quit the portal");
  
          int command = input.nextInt();
          switch (command) {
              case 1:
                  InputController.deposit();
                  break;
              case 2:
                  InputController.balance();
                  break;
              case 3:
                  User user = InputController.register();
                  accountHolders[index] = user;
                  index++;
                  break;
  
                  default:
                  System.out.println("Wrong input! please enter a number between 1 - 4!!!");
                  break;
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class Account {
  private int uniID;
  private int password;
  private int balance;
  private String cardNum;
  
  public int getUniID() {
      return uniID;
  }
  
  public int getPassword() {
      return password;
  }
  
  public int getBalance() {
      return balance;
  }
  public void makeDeposit(int amount) {
      this.balance = this.balance + amount;
  }
  
  public Account(int password, int balance) {
      this.password = password;
      this.balance = balance;
  
      Random rand = new Random();
      this.uniID = rand.nextInt(100);
  
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class User {
  private String name;
  private Account account;
  
  public String getName() {
      return name;
  }
  
  
  public Account getAccount() {
      return account;
  }
  
  
  
  public User(String name, Account account) {
      this.name = name;
      this.account = account;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class InputController {
  
  static Scanner input = new Scanner(System.in);
  
  public static User register() {
      System.out.print("Enter your name: ");
      String name = input.next();
      System.out.print("Enter your password: ");
      int password = input.nextInt();
      System.out.print("Please enter the amount of your initial deposit: ");
      int balance = input.nextInt();
  
      Account account = new Account(password, balance);
  
      User user = new User(name, account);
  
      System.out.print("Your account number is: " + account.getUniID());
  
  
      return user;
  
  
  }
  
  public static void balance() {
  
      int index = findAccount();
  
      if (index != -1) {
          System.out.print("Enter your password: ");
          int password = input.nextInt();
          if (Main.accountHolders[index].getAccount().getPassword() == password) {
              System.out.println("Your balance is: " +
                      Main.accountHolders[index].getAccount().getBalance());
          } else {
              System.out.println("Wrong password");
          }
  
      }
  
  
  
  }
  
  public static void deposit() {
  
  
          int index = findAccount();
          if (index != -1) {
              System.out.print("Enter the required amount: ");
              int money = input.nextInt();
              Main.accountHolders[index].getAccount().makeDeposit(money);
              System.out.println("Deposit successful");
          }
      }
  
  
      private static int findAccount() {
  
          System.out.print("Please Enter your account number: ");
          int accountNum = input.nextInt();
  
          for (int i = 0; i &lt; Main.index; i++) {
  
              User user = Main.accountHolders[i];
              int id = user.getAccount().getUniID();
  
              if (id == accountNum) {
                  return i;
  
              } else if (id != accountNum){
                  System.out.println("Account number not found");
  
              }
  
          }
  
          return -1;
      }
  }
  </code></pre>
  
  <p>sorry, It's a bit long but right now this the whole thing. I want to introduce a new variable for credit card number users every time they register a new account.</p>