首页 > 代码库 > 【java】彩票中奖码生成器:java.util.Random里的方法public int nextInt(int bound)

【java】彩票中奖码生成器:java.util.Random里的方法public int nextInt(int bound)

技术分享
 1 package 彩票中奖码生成器;
 2 
 3 import java.util.Random;
 4 
 5 public class TestRandom {
 6     public static void main(String[] args) {
 7         Random random=new Random();
 8         int[] numbers=new int[6];
 9         int index=0;
10         while(index<numbers.length){
11             int num=random.nextInt(50);
12             if(!isContains(numbers,num))
13                 numbers[index++]=num;
14         }
15         java.util.Arrays.sort(numbers);
16         for(int i:numbers){
17             System.out.print(i+",");
18         }
19     }
20     public static boolean isContains(int[] tmp,int num){
21         if(num==0)
22             return true;
23         for(int i=0;i<tmp.length;i++){
24             if(tmp[i]==num)
25                 return true;            
26         }
27         return false;
28     }
29 }
View Code

 

【java】彩票中奖码生成器:java.util.Random里的方法public int nextInt(int bound)