`
chenhsong
  • 浏览: 42547 次
  • 性别: Icon_minigender_1
  • 来自: 洛阳
社区版块
存档分类
最新评论

双色球概率分析

阅读更多
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package test;
import java.math.BigInteger;
import java.math.BigDecimal;
/**
 * 2011-3-19
 * @author Jasper
 */
public class RedandBlue {
    public static void main(String[] args) {
        System.out.println("双色球中奖概率(6/33+1/16):");
        BigInteger allOdds = getOdds(33,6).multiply(getOdds(16,1));
        BigInteger odds1 = getOdds(6,6).multiply(getOdds(1,1));
        BigInteger odds2 = getOdds(6,6).multiply(getOdds(15,1));
        BigInteger odds3 = getOdds(6,5).multiply(getOdds(27,1)).multiply(getOdds(1,1));
        BigInteger odds4 = getOdds(6,5).multiply(getOdds(27,1)).multiply(getOdds(15,1)).add(getOdds(6,4).multiply(getOdds(27,2)).multiply(getOdds(1,1)));
        BigInteger odds5 = getOdds(6,4).multiply(getOdds(27,2)).multiply(getOdds(15,1)).add(getOdds(6,3).multiply(getOdds(27,3)).multiply(getOdds(1,1)));
        BigInteger odds6 = getOdds(6,2).multiply(getOdds(27,4)).multiply(getOdds(1,1)).add(getOdds(6,1).multiply(getOdds(27,5)).multiply(getOdds(1,1))).add(getOdds(27,6).multiply(getOdds(1,1)));
        BigInteger odds1_7 = odds1.add(odds2).add(odds3).add(odds4).add(odds5).add(odds6);
        BigInteger odds7 = allOdds.add(odds1_7.negate());
        String odds11 = BigDecimal.valueOf(odds1.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),8,BigDecimal.ROUND_HALF_EVEN).toPlainString();
        String odds21 = BigDecimal.valueOf(odds2.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),8,BigDecimal.ROUND_HALF_EVEN).toPlainString();
        String odds31 = BigDecimal.valueOf(odds3.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),8,BigDecimal.ROUND_HALF_EVEN).toPlainString();
        String odds41 = BigDecimal.valueOf(odds4.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),4,BigDecimal.ROUND_HALF_EVEN).toPlainString();
        String odds51 = BigDecimal.valueOf(odds5.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),4,BigDecimal.ROUND_HALF_EVEN).toPlainString();
        String odds61 = BigDecimal.valueOf(odds6.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),4,BigDecimal.ROUND_HALF_EVEN).toPlainString();
        String odds71 = BigDecimal.valueOf(odds7.longValue()).divide(BigDecimal.valueOf(allOdds.longValue()),4,BigDecimal.ROUND_HALF_EVEN).toPlainString();
 
        double check=(new Double(odds11))+(new Double(odds21))+(new Double(odds31))+(new Double(odds41))+(new Double(odds51))+(new Double(odds61))+(new Double(odds71));
        System.out.println("一等奖(中6+1)中奖概率:"+odds1+"/"+allOdds+"="+odds11);
        System.out.println("二等奖(中6+0):"+odds2+"/"+allOdds+"="+odds21);
        System.out.println("三等奖(中5+1)(3000元)中奖概率:"+odds3+"/"+allOdds+"="+odds31);
        System.out.println("四等奖(中5+0或4+1)(200元)中奖概率:"+odds4+"/"+allOdds+"="+odds41);
        System.out.println("五等奖(中4+0或3+1)(10元)中奖概率:"+odds5+"/"+allOdds+"="+odds51);
        System.out.println("六等奖(中2+1或1+1或0+1)(5元)中奖概率:"+odds6+"/"+allOdds+"="+odds61);
        System.out.println("不中奖概率:"+odds7+"/"+allOdds+"="+odds71);
        System.out.println("验证结果,概率相加之和为"+check);
    }
 
    private static BigInteger getOdds(Integer n,Integer k) {
        BigInteger lotteryOdds = BigInteger.valueOf(1);
        for(int i = 1; i<=k;i++) {
            lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n-i+1)).divide(BigInteger.valueOf(i));
        }
        return lotteryOdds;
    }
}

 结果:

run:
双色球中奖概率(6/33+1/16):
一等奖(中6+1)中奖概率:1/17721088=0.00000006
二等奖(中6+0):15/17721088=0.00000085
三等奖(中5+1)(3000元)中奖概率:162/17721088=0.00000914
四等奖(中5+0或4+1)(200元)中奖概率:7695/17721088=0.0004
五等奖(中4+0或3+1)(10元)中奖概率:137475/17721088=0.0078
六等奖(中2+1或1+1或0+1)(5元)中奖概率:1043640/17721088=0.0589
不中奖概率:16532100/17721088=0.9329
验证结果,概率相加之和为1.00001005
成功生成(总时间:0 秒)
 
祝大家中大奖,交好运!
<!-- -->

 

0
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics