美文网首页
Python 验证双色球中奖概率

Python 验证双色球中奖概率

作者: 我的小小笔尖 | 来源:发表于2023-05-19 08:42 被阅读0次

    验证规则:
    从前面六期开奖号码中,每期随机选一个红球数字,组成6个红球数字作为当前的自选号码,验证中奖概率。
    中4个红球,10元;
    中5个红球,200元;
    中6个红球,100万元。

    验证方式:
    每期100元,验证历史所有的开奖数据。

    验证结果(十次):

    验证期数 2994 中奖期数 532
    购彩成本 299400 中奖金额 14830
    中奖概率 17.77 % 返现概率 4.95 %

    验证期数 2994 中奖期数 533
    购彩成本 299400 中奖金额 12160
    中奖概率 17.8 % 返现概率 4.06 %

    验证期数 2994 中奖期数 538
    购彩成本 299400 中奖金额 1012070
    中奖概率 17.97 % 返现概率 338.03000000000003 %

    验证期数 2994 中奖期数 526
    购彩成本 299400 中奖金额 12980
    中奖概率 17.57 % 返现概率 4.34 %

    验证期数 2994 中奖期数 522
    购彩成本 299400 中奖金额 13360
    中奖概率 17.43 % 返现概率 4.46 %

    验证期数 2994 中奖期数 543
    购彩成本 299400 中奖金额 13800
    中奖概率 18.14 % 返现概率 4.61 %

    验证期数 2994 中奖期数 541
    购彩成本 299400 中奖金额 13040
    中奖概率 18.07 % 返现概率 4.36 %

    验证期数 2994 中奖期数 486
    购彩成本 299400 中奖金额 11310
    中奖概率 16.23 % 返现概率 3.7800000000000002 %

    验证期数 2994 中奖期数 517
    购彩成本 299400 中奖金额 2012040
    中奖概率 17.27 % 返现概率 672.02 %

    验证期数 2994 中奖期数 488
    购彩成本 299400 中奖金额 12350
    中奖概率 16.3 % 返现概率 4.12 %

    Python代码:

    import requests
    import os
    import random
    
    gl_cnt_times = 0 # 开奖期数
    gl_cnt_wins = 0 # 中奖期数
    gl_cnt_cost = 0 # 花费金额
    gl_cnt_money = 0 # 中奖金额
    
    # 按规则自选红球号码
    def ruleOptionalNumbers(dataList):
        # 选择n注号码
        n = 5 * 10
        global gl_cnt_cost
        gl_cnt_cost = gl_cnt_cost + n * 2
        isWin = False # 当期是否有中奖
        for i in range(n):
            optional_numbers = []
            for rowIdx, data_cols in enumerate(dataList):
                random.shuffle(data_cols) # 打乱数组顺序
                if rowIdx < 6:
                    while True:
                        optionalNumber = data_cols[random.randrange(0, 6, 1)] # 随机选择号码(0-5)
                        if not optionalNumber in optional_numbers:
                            optional_numbers.append(optionalNumber)
                            break
                else:
                    optional_numbers.sort()
                    if calculateOptionalNumbers(data_cols, optional_numbers):
                        isWin = True
        return isWin
    
    # 计算是否中奖
    def calculateOptionalNumbers(data_cols, optional_numbers):
        cnt = 0
        for num in optional_numbers:
            if num in data_cols:
                cnt = cnt + 1
        if cnt >= 4:
            global gl_cnt_money
            if cnt==4:
                gl_cnt_money = gl_cnt_money + 10
                # print ('中奖了,10元')
            if cnt==5:
                gl_cnt_money = gl_cnt_money + 200
                # print ('中奖了,200元')
            if cnt==6:
                gl_cnt_money = gl_cnt_money + 1000000
                # print ('中奖了,1,000,000元')
            # print (data_cols)
            # print (optional_numbers)
            return True
        else:
            return False
    
    def main():
        # 双色球开奖数据下载地址
        # https://www.17500.cn/getData/ssq.TXT
    
        # 处理数据
        originalFile = open(os.path.join('./', 'ssq_original.txt'), "r")
        data_row_list = [] # 保存最近的7期开奖号码
        global gl_cnt_times
        global gl_cnt_wins
        while True:
            data_row = originalFile.readline().strip('\n')  # 读取一行,并去掉换行符
            if data_row:
                data_cols = data_row.split(' ') # 行字符串转数组
                data_cols = data_cols[2:8] # 获取红球号码
                data_row_list.append(data_cols)
                if len(data_row_list)==7:
                    # if gl_cnt_times >= 2000:
                    #     break # 只验证一千期
                    # 按规则自选红球号码并判断是否中奖
                    gl_cnt_times = gl_cnt_times + 1
                    if ruleOptionalNumbers(data_row_list):
                        gl_cnt_wins = gl_cnt_wins + 1
                    del data_row_list[0]
            else:
                break
        originalFile.close()
    
        # 计算中奖概率
        print ('验证期数', gl_cnt_times, '中奖期数', gl_cnt_wins)
        print ('购彩成本', gl_cnt_cost, '中奖金额', gl_cnt_money)
        print ('中奖概率', round(gl_cnt_wins/gl_cnt_times,4)*100, '%' , '返现概率', round(gl_cnt_money/gl_cnt_cost,4)*100, '%')
    
    if __name__ == '__main__':
        main()
    

    相关文章

      网友评论

          本文标题:Python 验证双色球中奖概率

          本文链接:https://www.haomeiwen.com/subject/lnwgsdtx.html