首页 > 其他 > 详细

生成6位随机数工具类

时间:2021-03-08 19:55:57      阅读:31      评论:0      收藏:0      [点我收藏+]
public class Ints6Utils {

    public static int getInts6() {
        int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        Random rand = new Random();
        for (int i = 10; i > 1; i--) {
            int index = rand.nextInt(i);
            int tmp = array[index];
            array[index] = array[i - 1];
            array[i - 1] = tmp;
        }
        int result = 0;
        for (int i = 0; i < 6; i++) {
            result = result * 10 + array[i];
            if (i == 5 && result <= 99999) {
                result = result * 10 + array[i + 1];
            }
        }
        return result;
    }
}

 

showtooltip

生成6位随机数工具类

原文:https://www.cnblogs.com/coding8832/p/14500168.html

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