JAVA生成六位随机数

 

 

 

/**
     * 生成六位随机数
     * @return
     */
    public static String getSixNum() {
        String str = "0123456789";
        StringBuilder sb = new StringBuilder(4);
        for (int i = 0; i < 6; i++) {
            char ch = str.charAt(new Random().nextInt(str.length()));
            sb.append(ch);
        }
        return sb.toString();
    }

 

posted @ 2019-03-13 16:37  yvioo  阅读(510)  评论(0编辑  收藏  举报