Java generates a 6-bit random string containing letters and numbers _java

Source: Internet
Author: User

This example of this article for you to share the Java generated 6-bit random string implementation code, specific content as follows

Package com.amos.tools;
Import java.util.ArrayList;
Import java.util.List;
 
Import Java.util.Random;
    public class Invertcodegenerator {public static void main (string[] args) {//TODO auto-generated stub
    List<string> results=gencodes (6,100);
  System.out.println (Results.size ()); public static list<string> gencodes (int length,long num) {list<string> results=new ARRAYLIST&L T
     
    String> ();   
           
      for (int j=0;j<num;j++) {String val = "";   
      Random Random = new Random (); for (int i = 0; i < length; i++) {String charornum = random.nextint (2)% 2 = 0? "Char": "num"; Output letter or number if ("Char". Equalsignorecase (Charornum))//String {int choice = Random.nextint (2)% 2 = 0? 65:97;   
        Gets the uppercase or lowercase letter val + = (char) (Choice + random.nextint (26));  else if ("num". Equalsignorecase (Charornum))//number 
        {val = string.valueof (Random.nextint (10));
      } val=val.tolowercase ();
      if (Results.contains (val)) {continue;
      }else{Results.add (Val);
           
        
    } return results;

 }  
   
 
}

The above is the entire content of this article, I hope to learn Java program to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.