首页 > 其他 > 详细

RandomUtils

时间:2016-01-26 23:35:08      阅读:508      评论:0      收藏:0      [点我收藏+]

package com.cc.hkjc.util;

import java.util.Random;

public class RandomUtils {
    /**
     * 获取count个随机数
     * @param count 随机数个数
     * @return
     */
    public static String game(int count){
        StringBuffer sb = new StringBuffer();
        String str = "0123456789";
        Random r = new Random();
        for(int i=0;i<count;i++){
            int num = r.nextInt(str.length());
            sb.append(str.charAt(num));
            str = str.replace((str.charAt(num)+""), "");
        }
        return sb.toString();
    }
    
    //测试方法-随机显示4为数字
    public static void main(String[] args) {
        System.out.println(RandomUtils.game(4));
    }
}

RandomUtils

原文:http://www.cnblogs.com/strive-study/p/5161761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!