Java Random create random String example 1

Description

Java Random create random String example 1


public class Main {

   public static void main(String[] args) {
      java.util.Random r = new java.util.Random();
      int i = 1, n = 0;
      char c;//from  w w w  .j a  va2 s  . c o  m
      String str = "";
      for (int t = 0; t < 3; t++) {
         while (true) {
            i = r.nextInt(10);
            if (i > 5 && i < 10) {

               if (i == 4) {
                  i = 90;
                  n = 90;
                  break;
               }
               if (i != 90) {
                  n = i * 10 + r.nextInt(10);
                  while (n < 65) {
                     n = i * 10 + r.nextInt(10);
                  }
               }

               break;
            }
         }
         c = (char) n;
         str = String.valueOf(c) + str;
      }
      while (true) {
         i = r.nextInt(10000000);
         if (i > 999999)
            break;
      }
      str = str + i;
      System.out.println(str);

   }
}



PreviousNext

Related