码迷,mamicode.com
首页 > 其他好文 > 详细

生成6位随机数

时间:2015-09-06 17:48:48      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

public static void main(String[] args) {
//创建一个含有随机数的长度为10的数组
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;
//从上面创建的随机数数组中取6位组成6位随机数
for(int i = 0; i < 6; i++)
result = result * 10 + array[i];
}

生成6位随机数

标签:

原文地址:http://www.cnblogs.com/nana-blog/p/4786332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!