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.