Topic: 跪求:如何使用JAVA中的随机函数产生不重复的数! |
Print this page |
1.跪求:如何使用JAVA中的随机函数产生不重复的数! | Copy to clipboard |
Posted by: wwwzjcom Posted on: 2006-06-23 14:00 如何使用JAVA中的随机函数产生不重复的数,产生的数不能有零的出现,最好帮我写上代码,有谁能帮帮我啊,谢谢!! |
2.Re:跪求:如何使用JAVA中的随机函数产生不重复的数! [Re: wwwzjcom] | Copy to clipboard |
Posted by: Freax Posted on: 2006-06-23 16:43 Random rd = new Random(); int i = rd.NextInt(100)+1 |
3.Re:跪求:如何使用JAVA中的随机函数产生不重复的数! [Re: wwwzjcom] | Copy to clipboard |
Posted by: wwwzjcom Posted on: 2006-06-23 21:32 public class RandomTest { private static final int SET_SIZE = 6; public static final int RANDOM_MAX_VALUE = 33; private static Random random = new Random(); public static void main(String[] args) { Set set = new HashSet(); while (set.size() < SET_SIZE ) { Integer integer =new Integer(random.nextInt(RANDOM_MAX_VALUE) ); set.add(integer); } Iterator it = set.iterator(); while(it.hasNext()) { System.out.println("Output A ball:"+it.next()); } int i; i=random.nextInt(16)+1; System.out.print("Output B ball:"+i); } } 如何屏蔽在A球输出中输出0? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |