`
qq986945193
  • 浏览: 81815 次
  • 性别: Icon_minigender_2
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

【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("-", ""));
    }

}
<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics