yujian
2019-03-12 4a05f1c9c508ab7f10c5eae22a5c716f5454ca02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.fanli.random;
 
import com.alibaba.fastjson.JSON;
 
import java.util.ArrayList;
import java.util.List;
 
public class ExtractGift {
 
    /**
     * 生成奖项
     * 
     * @return
     */
    public static RandomGift generateAward() {
        List<RandomGift> giftList = new ArrayList<RandomGift>();
        giftList.add(new RandomGift(1, "\r\n" + 
                "                            na****La,抽中华为手机\r\n" + 
                "                        ", 1));
        giftList.add(new RandomGift(2, "100", 3));
        giftList.add(new RandomGift(3, "50", 30));
        giftList.add(new RandomGift(4, "30", 30));
        giftList.add(new RandomGift(5, "20", 26));
        giftList.add(new RandomGift(6, "10", 10));
 
        long result = (1 + Math.round(Math.random() * (99)));
        System.out.println("result:"+result);
        
        int minRange = 0;
        int maxRange = 0;
        RandomGift returnobj = null;
        
        for (int i = 0; i < giftList.size(); i++) {
            RandomGift obj2 = giftList.get(i);
            int probability = obj2.getProbability();
            
            maxRange = maxRange + probability;
            minRange = 100 - maxRange;
            
            System.out.println("maxRange: "+maxRange);
            System.out.println("minRange: "+minRange);
            
            if (result > minRange && result <= maxRange) {
                returnobj = obj2;
                break;
            }
        }
        
        return returnobj;
    }
 
 
    public static void main(String[] args) {
        for (int i =0 ; i<10 ;i ++) {
            System.out.println(1+ Math.round(Math.random() * (3)));
        }
    }
 
}