javarandom重复_[代码]java实现⽣成重复或不重复的随机数List list = new ArrayList();
java.util.Random random = new java.util.Random();
while (list.size() < 100) { //假定产⽣100个随机数
Integer ii = new Int(20)); //随机数都在20以内
if (!ains(ii)) {
list.add(ii);
}
System.out.println( "随机数产⽣结果" + String());
}
1.public class RandomGen {java生成随机数的方法
2.
3. private static Random random = new Random();
4.
5.
6. public static String getRandomNumber(String[] range,int rangeLength,int length){
7. StringBuffer sb = new StringBuffer();
8. for(int i=0;i
9. sb.append(String.valueOf(Int(rangeLength)]));
10. }
11. String();
12. }
13. public static void main(String[] args) {
14. String[] range = {"0","1","2","3","4","5","6","7","8","9"};
15. System.out.println(getRandomNumber(range, 10, 8));
16.
17. }
18.}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论