Lotto JAVA analog data (for reference)

Stand idly wrote a big lottery data rule, do not say go stick on the code.

 

private List<String> hiveMeAPrize(){
        List<String> strings = new ArrayList<>();
        for(int x = 0; x < 5000; x++){
            String s = "";
            int[] a = randomNums(1, 35, 5);
            int[] b = randomNums(1, 12, 2);
            Arrays.sort(a);
            Arrays.sort(b);
            for(int i : a){
                s += i +" ";
            }
            s += "----";
            for(int i : b){
                s += i +" ";
            }
            strings.add(s);
        }
        List<String> stringss = new ArrayList<>();
        for(String s : strings){
            int a = -1;
            for(String ss : strings){
                if(s.equals(ss)){
                    a++;
                }
            }
            stringss.add(s += "重复次数" + a);
        }
        return stringss;
    }

    public static int[] randomNums(int min, int max, int n) {
        int range = max - min + 1;
        if (min > max || n < 0 || n > range) {
            return null;
        }
        int[] nums = new int[n];
        List<Integer> list = new ArrayList<Integer>(n);
        while (list.size() < n) {
            int num = new Random().nextInt(range) + min;
            if (!list.contains(Integer.valueOf(num))) {
                nums[list.size()] = num;
                list.add(Integer.valueOf(num));
            }
        }
        return nums;
    }

Determine whether to repeat the logic casually written. oo !!!

Published 39 original articles · won praise 19 · views 60000 +

Guess you like

Origin blog.csdn.net/u010090644/article/details/83930790