Random generation of serial numbers

Source: Internet
Author: User

Package Test;import Java.text.dateformat;import Java.text.simpledateformat;import java.util.calendar;import Java.util.date;import java.util.hashmap;import java.util.map;/* * Generate serial number * @author Huifeidexiaobenzhu * @time 2014-11-27 * /public class Createseriano {private static map<string,string> map=new hashmap<string,string> ();p rivate static string statnum= "000001";/** * Get Month Day * @return */public String getTime () {Calendar cal=calendar.getinstance ();  Cal.settime (New Date ()));D Ateformat df=new simpledateformat ("YyyyMMdd"); return Df.format (Cal.gettime ());}  /** * Determine if the serial number is to the last * @param s * @return */public string Getlastsixnum (String s) {string Rs=s;int i=integer.parseint (RS); int f= (int) (Math.random () *100000) i++;rs= "" +f;for (int j=rs.length (); j<6;j++) {rs= "0" +RS;} return RS;} /** * Generates non-duplicated number yoke * @return */public synchronized string Getnum () {string yearamon=gettime (); String Last6num=map.get (Yearamon), if (last6num==null) {map.put (Yearamon, statnum);} Else{map.put (Yearamon, Getlastsixnum (lAst6num));} Return Yearamon+map.get (Yearamon);} /** * Main Test * @param args */public static void main (string[] args) {Createseriano t=new Createseriano (); for (int i=0;i< 10;i++) {System.out.println (T.getnum ());}}}

  

Random generation of serial numbers

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.