2019-10-02-双色球数字概率分析

双色球的规则是红色球从数字1到33中选出6个,蓝色球从1到16中选出1个。

假定福彩中心没有作弊,概率完全随机,蓝色球随机没有办法分析,所以每个数字出现概率为1/16。

这里我们来分析一下红色球。红色球的结果可能有C(33,6) = 1107568种(C33)

我们把红色球出现的号码从小到大排列,分别叫做红1到红6.

红1最少值是1,最大值是28.

红1为1的可能性是先选一个1出来,其余的32个球中选出5个来的所有可能性。
C(32,5)/C(33,6) = 201376/1107568 = 18.18%

红1为2的可能性是先排除号码1,然后选一个2出来,其余的31个球中选出5个来的所有可能性。
C(31,5)/C(33,6) = 169911/1107568 = 15.34%

依次类推,
红1为3的概率是
C(30,5)/C(33,6) = 142506/1107568 = 12.86%

继续分析规律。

红2最少值是2,最大值是29.

红2为2的可能性是先选一个1号球当红1,然后选一个2号球当红2,其余31个球中选4个出来的所有可能性。
C(31,4)/C(33,6) = 31465/1107568 = 2.84%

红2为3的可能性是先选一个1号球或者2号球当红1,然后选一个3号球当红2,其余30个球中选4个出来的所有可能性。
C(2,1)C(30,4)/C(33,6) = 227405/1107568 = 4.95%

所以通用的概率公式就是第n个球等于i的可能性除以总的可能性。

C(i-1,n-1)*C(33-i,6-n)/C(33,6)

写成java代码就是:

// LotteryChance.java
// javac LotteryChance.java
// java LotteryChance
public class LotteryChance {

    public static double factorial(int n) {
        double[] f = new double[n+1];
        f[0] = f[1] = 1;
        for (int i = 2; i <= n; i++)
            f[i] = f[i-1] * i;
        return f[n];
    }

    public static double combination(int n, int r){
        if(n == 0 || r == 0 || n == r) return 1;
        return Math.round(factorial(n)/(factorial(r)*factorial(n-r)));
    }

    public static void main(String[] args) {
        double all = 1107568; // combination(33,6);
        double[][] chance = new double[6][28];
        for(int n = 1; n < 7; n++){
            System.out.println("the "+ n +"th number:");
            for(int i = n; i < 34-(6-n); i++) {
                chance[n-1][i-n] = combination((i-1), (n-1))*combination((33-i), (6-n))/all;
                System.out.println("the chance = "+i+" is : "+100*chance[n-1][i-n]+"%.");
            }
        }
    }
}

输出结果是:

the 1th number:
the chance = 1 is : 18.181818181818183%.
the chance = 2 is : 15.340909090909092%.
the chance = 3 is : 12.866568914956012%.
the chance = 4 is : 10.722140762463344%.
the chance = 5 is : 8.87349580341794%.
the chance = 6 is : 7.288942981379021%.
the chance = 7 is : 5.939138725568092%.
the chance = 8 is : 4.796996662958843%.
the chance = 9 is : 3.8375973303670743%.
the chance = 10 is : 3.0380978865406005%.
the chance = 11 is : 2.3776418242491655%.
the chance = 12 is : 1.8372686823743551%.
the chance = 13 is : 1.3998237579995088%.
the chance = 14 is : 1.0498678184996315%.
the chance = 15 is : 0.7735868136313075%.
the chance = 16 is : 0.558701587622611%.
the chance = 17 is : 0.3943775912630195%.
the chance = 18 is : 0.2711345939933259%.
the chance = 19 is : 0.1807563959955506%.
the chance = 20 is : 0.11620054028285397%.
the chance = 21 is : 0.0715080247894486%.
the chance = 22 is : 0.041713014460511684%.
the chance = 23 is : 0.02275255334209728%.
the chance = 24 is : 0.01137627667104864%.
the chance = 25 is : 0.005056122964910506%.
the chance = 26 is : 0.00189604611184144%.
the chance = 27 is : 5.417274605261257E-4%.
the chance = 28 is : 9.028791008768762E-5%.
the 2th number:
the chance = 2 is : 2.840909090909091%.
the chance = 3 is : 4.948680351906158%.
the chance = 4 is : 6.433284457478006%.
the chance = 5 is : 7.394579836181616%.
the chance = 6 is : 7.9227641101945885%.
the chance = 7 is : 8.098825534865579%.
the chance = 8 is : 7.994994438264738%.
the chance = 9 is : 7.675194660734149%.
the chance = 10 is : 7.195494994438264%.
the chance = 11 is : 6.604560622914349%.
the chance = 12 is : 5.944104560622914%.
the chance = 13 is : 5.2493390924981576%.
the chance = 14 is : 4.549427213498404%.
the chance = 15 is : 3.8679340681565373%.
the chance = 16 is : 3.2232783901304476%.
the chance = 17 is : 2.6291839417534635%.
the chance = 18 is : 2.0951309535847913%.
the chance = 19 is : 1.6268075639599553%.
the chance = 20 is : 1.2265612585412362%.
the chance = 21 is : 0.8938503098681074%.
the chance = 22 is : 0.6256952169076753%.
the chance = 23 is : 0.41713014460511677%.
the chance = 24 is : 0.2616543634341187%.
the chance = 25 is : 0.1516836889473152%.
the chance = 26 is : 0.07900192132672666%.
the chance = 27 is : 0.03521228493419817%.
the chance = 28 is : 0.012188867861837828%.
the chance = 29 is : 0.002528061482455253%.
the 3th number:
the chance = 3 is : 0.36656891495601174%.
the chance = 4 is : 0.9897360703812317%.
the chance = 5 is : 1.7746991606835878%.
the chance = 6 is : 2.640921370064863%.
the chance = 7 is : 3.5212284934198173%.
the chance = 8 is : 4.360906057235312%.
the chance = 9 is : 5.116796440489433%.
the chance = 10 is : 5.756395995550612%.
the chance = 11 is : 6.256952169076752%.
the chance = 12 is : 6.604560622914349%.
the chance = 13 is : 6.793262354997616%.
the chance = 14 is : 6.824140820247606%.
the chance = 15 is : 6.704419051471332%.
the chance = 16 is : 6.446556780260895%.
the chance = 17 is : 6.0673475578926075%.
the chance = 18 is : 5.5870158762261095%.
the chance = 19 is : 5.028314288603499%.
the chance = 20 is : 4.415620530748451%.
the chance = 21 is : 3.774034641665342%.
the chance = 22 is : 3.128476084538376%.
the chance = 23 is : 2.502780867630701%.
the chance = 24 is : 1.9187986651835371%.
the chance = 25 is : 1.3954899383152999%.
the chance = 26 is : 0.9480230559207201%.
the chance = 27 is : 0.5868714155699695%.
the chance = 28 is : 0.31691056440778353%.
the chance = 29 is : 0.13651532005258368%.
the chance = 30 is : 0.036656891495601175%.
the 4th number:
the chance = 4 is : 0.036656891495601175%.
the chance = 5 is : 0.13651532005258368%.
the chance = 6 is : 0.31691056440778353%.
the chance = 7 is : 0.5868714155699695%.
the chance = 8 is : 0.9480230559207201%.
the chance = 9 is : 1.3954899383152999%.
the chance = 10 is : 1.9187986651835371%.
the chance = 11 is : 2.502780867630701%.
the chance = 12 is : 3.128476084538376%.
the chance = 13 is : 3.774034641665342%.
the chance = 14 is : 4.415620530748451%.
the chance = 15 is : 5.028314288603499%.
the chance = 16 is : 5.5870158762261095%.
the chance = 17 is : 6.0673475578926075%.
the chance = 18 is : 6.446556780260895%.
the chance = 19 is : 6.704419051471332%.
the chance = 20 is : 6.824140820247606%.
the chance = 21 is : 6.793262354997616%.
the chance = 22 is : 6.604560622914349%.
the chance = 23 is : 6.256952169076752%.
the chance = 24 is : 5.756395995550612%.
the chance = 25 is : 5.116796440489433%.
the chance = 26 is : 4.360906057235312%.
the chance = 27 is : 3.5212284934198173%.
the chance = 28 is : 2.640921370064863%.
the chance = 29 is : 1.7746991606835878%.
the chance = 30 is : 0.9897360703812317%.
the chance = 31 is : 0.36656891495601174%.
the 5th number:
the chance = 5 is : 0.002528061482455253%.
the chance = 6 is : 0.012188867861837828%.
the chance = 7 is : 0.03521228493419817%.
the chance = 8 is : 0.07900192132672666%.
the chance = 9 is : 0.1516836889473152%.
the chance = 10 is : 0.2616543634341187%.
the chance = 11 is : 0.41713014460511677%.
the chance = 12 is : 0.6256952169076753%.
the chance = 13 is : 0.8938503098681074%.
the chance = 14 is : 1.2265612585412362%.
the chance = 15 is : 1.6268075639599553%.
the chance = 16 is : 2.0951309535847913%.
the chance = 17 is : 2.6291839417534635%.
the chance = 18 is : 3.2232783901304476%.
the chance = 19 is : 3.8679340681565373%.
the chance = 20 is : 4.549427213498404%.
the chance = 21 is : 5.2493390924981576%.
the chance = 22 is : 5.944104560622914%.
the chance = 23 is : 6.604560622914349%.
the chance = 24 is : 7.195494994438264%.
the chance = 25 is : 7.675194660734149%.
the chance = 26 is : 7.994994438264738%.
the chance = 27 is : 8.098825534865579%.
the chance = 28 is : 7.9227641101945885%.
the chance = 29 is : 7.394579836181616%.
the chance = 30 is : 6.433284457478006%.
the chance = 31 is : 4.948680351906158%.
the chance = 32 is : 2.840909090909091%.
the 6th number:
the chance = 6 is : 9.028791008768762E-5%.
the chance = 7 is : 5.417274605261257E-4%.
the chance = 8 is : 0.00189604611184144%.
the chance = 9 is : 0.005056122964910506%.
the chance = 10 is : 0.01137627667104864%.
the chance = 11 is : 0.02275255334209728%.
the chance = 12 is : 0.041713014460511684%.
the chance = 13 is : 0.0715080247894486%.
the chance = 14 is : 0.11620054028285397%.
the chance = 15 is : 0.1807563959955506%.
the chance = 16 is : 0.2711345939933259%.
the chance = 17 is : 0.3943775912630195%.
the chance = 18 is : 0.558701587622611%.
the chance = 19 is : 0.7735868136313075%.
the chance = 20 is : 1.0498678184996315%.
the chance = 21 is : 1.3998237579995088%.
the chance = 22 is : 1.8372686823743551%.
the chance = 23 is : 2.3776418242491655%.
the chance = 24 is : 3.0380978865406005%.
the chance = 25 is : 3.8375973303670743%.
the chance = 26 is : 4.796996662958843%.
the chance = 27 is : 5.939138725568092%.
the chance = 28 is : 7.288942981379021%.
the chance = 29 is : 8.87349580341794%.
the chance = 30 is : 10.722140762463344%.
the chance = 31 is : 12.866568914956012%.
the chance = 32 is : 15.340909090909092%.
the chance = 33 is : 18.181818181818183%.

从结果可以看出,
红1最有可能出现的数字是1-4, 最大可能性是1.
红2最有可能出现的数字是6-9, 最大可能性是7.
红3最有可能出现的数字是12-15, 最大可能性是14.
红4最有可能出现的数字是19-22, 最大可能性是20.
红5最有可能出现的数字是25-28, 最大可能性是27.
红6最有可能出现的数字是30-33, 最大可能性是33.

为了验证我的结果对不对,我写了一个程序来模拟双色球开奖,同时统计红1到红六出现的次数。
代码如下:

// Lottery.java
// javac Lottery.java
// java Lottery 100000000
import java.util.Arrays;
public class Lottery {
    public static int mostFrequent(int[] arr) {
        int max = 0;
        int f = 0;
        for(int i = 0; i< arr.length;i++) {
            if(arr[i] > max) {
                max = arr[i];
                f = i+1;
            }
        }
        return f;
    }
    public static void main(String[] args) {

        if(args.length < 1)
        {
            System.out.println("Proper Usage is: java Lottery 1000(or how many you want to try).");
            System.exit(0);
        }
        int n = Integer.parseInt(args[0]);    // choose this many elements
        int[] red = new int[33];
        int[] first = new int[34];
        int[] second = new int[34];
        int[] third = new int[34];
        int[] fourth = new int[34];
        int[] fifth = new int[34];
        int[] sixth = new int[34];
        for (int i = 0; i < 33; i++) {
            red[i] = i+1;
        }
        for(int c = 0; c < n; c++){
            for (int i = 0; i < 6; i++) {
                int r = i + (int)(Math.random()*(33-i));
                int t = red[r];
                red[r] = red[i];
                red[i] = t;
            }
            int[] result = new int[6];
            for (int i = 0; i<6; i++){
                result[i] = red[i];
            }
            Arrays.sort(result);
            first[result[0]-1]++;
            second[result[1]-1]++;
            third[result[2]-1]++;
            fourth[result[3]-1]++;
            fifth[result[4]-1]++;
            sixth[result[5]-1]++;
            if(args.length > 1){
                for (int i = 0; i < 6; i++){
                    System.out.print(result[i] + " ");
                }
                System.out.println();
                System.out.printf("red : %s\n", Arrays.toString(red));
            }
        }
        System.out.printf("first : %s\n", Arrays.toString(first));
        System.out.println(mostFrequent(first));
        System.out.printf("second : %s\n", Arrays.toString(second));
        System.out.println(mostFrequent(second));
        System.out.printf("third : %s\n", Arrays.toString(third));
        System.out.println(mostFrequent(third));
        System.out.printf("fourth : %s\n", Arrays.toString(fourth));
        System.out.println(mostFrequent(fourth));
        System.out.printf("fifth : %s\n", Arrays.toString(fifth));
        System.out.println(mostFrequent(fifth));
        System.out.printf("sixth : %s\n", Arrays.toString(sixth));
        System.out.println(mostFrequent(sixth));
    }
}

我执行java Lottery 100000000就是开奖一亿次, 结果如下:
first : [18181415, 15341925, 12865221, 10724122, 8871170, 7285535, 5942311, 4799328, 3837023, 3036659, 2376066, 1835980, 1400676,
1050389, 773613, 559635, 395151, 271204, 180914, 116457, 71486, 41806, 23020, 11295, 5043, 1939, 532, 85, 0, 0, 0, 0, 0, 0]
1
second : [0, 2840458, 4946818, 6432150, 7396106, 7919007, 8098429, 7991389, 7676025, 7199131, 6605295, 5949171, 5248256, 4550103,
3869756, 3221894, 2628698, 2095361, 1625266, 1227908, 893273, 626626, 417263, 262032, 151108, 78369, 35414, 12189, 2505, 0, 0, 0,
0, 0]
7
third : [0, 0, 365942, 988819, 1774042, 2639593, 3518744, 4361205, 5117636, 5755000, 6255513, 6602839, 6793753, 6830798, 6704630,
6444648, 6068836, 5590065, 5026655, 4413666, 3775953, 3128141, 2504301, 1918079, 1395028, 948685, 587462, 317071, 136088, 36808, 0
, 0, 0, 0]
14
fourth : [0, 0, 0, 36697, 136690, 316144, 586649, 947804, 1394881, 1916290, 2501275, 3128912, 3773469, 4415433, 5028612, 5588366,
6066877, 6445842, 6701330, 6826578, 6790441, 6606725, 6259293, 5757620, 5117888, 4361739, 3521883, 2643699, 1773521, 988768, 36657
4, 0, 0, 0]
20
fifth : [0, 0, 0, 0, 2529, 12318, 35027, 78985, 151410, 262359, 415583, 624312, 894846, 1226446, 1626489, 2094632, 2629957, 322277
7, 3867689, 4549473, 5247548, 5943771, 6600351, 7195273, 7673459, 7997888, 8101801, 7921915, 7397245, 6433408, 4949122, 2843387, 0
, 0]
27
sixth : [0, 0, 0, 0, 0, 87, 553, 1906, 4962, 11356, 22608, 41828, 71612, 115976, 181000, 271124, 394621, 559229, 773541, 1050827,
1401171, 1835353, 2378715, 3035969, 3838368, 4797255, 5937331, 7288578, 8877601, 10721731, 12864228, 15335628, 18186842, 0]
33

可以看到跟我上面的理论分析出来的结果一致。
上面结果里面first后面中括号里就是开奖一亿里面,
红1分别等于1到33的次数,当然红1最小等于1,最大等于28,不可能等于33.
可以看到出现的次数基本上等于我们上面理论分析的概率乘以一亿。
比如红1等于1的概率是18.181818181818183%,乘以一亿,理论出现次数是18181818,
这里的出现开奖结果次数是18181415,基本吻合。

同时出现次数也跟理论预言的一样,
红1出现次数最多的就是1。
红2出现次数最多的就是7。
红3出现次数最多的就是14。
红4出现次数最多的就是20。
红5出现次数最多的就是27。
红6出现次数最多的就是33。

至次,我们得到了双色球各个数字出现的概率。

进一步分析,所以红色球中奖概率最大的号码是什么呢?显然就是1,7,14,20,27,33。这个号码的中奖概率有多大呢?把上面的六个概率相乘,可以得出

18.181818181818183%*8.098825534865579%*6.824140820247606%*6.824140820247606%*8.098825534865579%*18.181818181818183%=1.0097518751278756E-6

所以这个号码的数学期望值是多少呢?
1.0097518751278756E-6*5000000/16=0.31554746097,

也就是0.31元,三毛钱,所以就算彩票没有作弊,你用两块钱买到的预期收益也只有三毛一。这就是彩票是一种智商税这种说法的由来。

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据