封裝生成唯一性ID的算法工具類

  import java.security.SecureRandom;
  import java.until.UUID;
  public abstract class IdUtils {
	private static SecureRandom random = new SecureRandom();
	/**封裝JDK自帶的UUID,通過Random數字生成,中間有-分割;
	*/
	public static String uuid(){
	 return UUID.randomUUID()。toString();
	}
	public static String uuid32() {
	 return UUID.randomUUID().toString().replaceAll("-","");
	}
//使用SecureRandom隨機生成Long。
	public static long randomLong(){
	 return random.nextLong();
	}
//基於Base62編碼的隨機生成Long
	public static String randomBase62(){
	 	return EncodeUtils.encodeBase62(random.nextLong());
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章