【JAVA】生成一個32位的隨機數。防止重複,保留唯一性

作者:程序員小冰,CSDN博客:http://blog.csdn.net/qq_21376985
QQ986945193 微博:http://weibo.com/mcxiaobing

import java.util.UUID;

/**
 * 
 * @author :程序員小冰
 * 
 * @新浪微博 :http://weibo.com/mcxiaobing
 * 
 * @version V1.0正式版 ctrl+y變小寫
 * 
 * @process 由於是隨機數,所以,下面的打印結果只是此次的結果
 * 
 * @Note http://blog.csdn.net/qq_21376985
 * 
 * @dateTime 2016-3-14下午10:47:31
 * 
 */
public class GetGuidRandom {
    public static void main(String[] args) {
        UUID uuid = UUID.randomUUID();
        /**
         * .{6c0222ed-e7f5-4cad-a717-a9abfb372239}
         */
        System.out.println(".{" + uuid.toString() + "}");
        /**
         * 6c0222ed-e7f5-4cad-a717-a9abfb372239
         */
        System.out.println(uuid.toString());
        /**
         * 36
         */
        System.out.println(uuid.toString().length());
        /**
         * 32
         */
        System.out.println(uuid.toString().replace("-", "").length());
        /**
         * 6c0222ede7f54cada717a9abfb372239
         */
        System.out.println(uuid.toString().replace("-", ""));
    }

}
發佈了160 篇原創文章 · 獲贊 48 · 訪問量 70萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章