Java implementation random Generation Uuid_java

Source: Internet
Author: User

Java implementation randomly generating UUID

 public class Idgenerator {private static long num=0;
    /** * Randomly generated UUID * @return/public static synchronized String Getuuid () {UUID uuid=uuid.randomuuid (); 
    String str = uuid.tostring ();
    String uuidstr=str.replace ("-", "");
  return uuidstr;
    /** * Generates a fixed UUID * @param name * @return/public static synchronized string Getuuid (string name) {
    UUID uuid=uuid.nameuuidfrombytes (Name.getbytes ()); 
    String str = uuid.tostring ();
    String uuidstr=str.replace ("-", "");
  return uuidstr; /** * Based on the date of the growth integer ID * @param args/public static synchronized long Getlongid () {String date=dateutil.ge
    Tdate2formatstring (New Date (), "yyyymmddhhmmsss");
    System.out.println ("original id=" +date);
    if (num>=99) num=0l;
    ++num;
    if (num<10) {date=date+00+num;
    }else{Date+=num;
  return long.valueof (date); }
  
}

The above is the entire contents of this article, I hope you can enjoy.

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.