分享

双色球中奖率分析(python)

 子歌-特斯拉 2016-05-31
    因为平时有买双色球,无奈屡买不中。故使用python完成了一个双色球分析程序,来提高中奖概率。下面就此程序,进行简单说明。   1、根据以往中奖纪录,进行分析,分析一段时间各个号码出现的次数,时间段分为三个,分别为一周(3期)、一月(13期)、一年(153期)。2、根据第一条分析结果,计算每个号出现的概率。3、给每个时间段(一周、月、年)统计出的号码出现概率,附一个权重,即用来表示,对最终分析结果的影响力。具体如下     (1)统计一年中(153期)出现最多的号码。       (2)  统计一月中(13期)出现最多的号码。       (3)  统计一周中(3期)出现最少的号码。       原因:在双色球的摇奖过程中,因为球的质量,形状问题,可能会导致某些号码总会比别的号码出现几率大。      故长期呢,分析出现次数多的,短期内,分析出现次数少的,作为将来出现概率大的号码。    4、根据第三条计算方法,计算出每个号码的总权重(即综合各个时间段的权重),每个时间段的权重比率,采用黄金分割比率,为(4.236,1.618,2.618)作为(年、月、日)的比率。5、根据以上统计结果,计算出将来出现几率最大的号码。   1、计算将来中奖概率最大的号码。2、随机产生一注。3、自选号码,计算自选号码的中奖概率。
random re shuangseqiu(): (self): self.quanzhong = [2.618,1.618,4.236] self.qishu = [4,13,153] self.data_long = [,,] self.fle = self.red_dict = {} self.blue_dict = {} self.red_rate = {} self.blue_rate = {} self.red_qz = [] self.blue_qz = [] i range(1,34): self.(i,self.red_dict) self.(i,self.red_rate) i range(1,17): self.(i,self.blue_dict) self.(i,self.blue_rate) (self,num ,color_dict): color_dict[str(num)] = {} x range(len(self.data_long)): color_dict[str(num)][self.data_long[x]] = 0 (self,num, color_dict, data_long): color_dict[str(num)][data_long] += 1 (self,ball_lst,data_long): i range(6): self.(ball_lst[i],self.red_dict, data_long) self.(ball_lst[6],self.blue_dict,data_long) (self): ball_file = open(self.fle, ) ball_lst = ball_file.readline() i range(1,self.qishu[2]): ball_lst = ball_file.readline().split() ball_lst = ball_lst[4:] i <= self.qishu[0]:="">(ball_lst,self.data_long[0]) i <= self.qishu[1]:="">(ball_lst,self.data_long[1]) self.(ball_lst,self.data_long[2]) ball_file.close() (self,qishu,data_long): redall = qishu * 6 blueall = qishu * 1 i range(1,34): self.red_rate[str(i)][data_long] = self.red_dict[str(i)][data_long]/redall i range(1,17): self.blue_rate[str(i)][data_long] = self.blue_dict[str(i)][data_long]/blueall (self): i range(len(self.data_long)): self.(self.qishu[i],self.data_long[i]) (self,num,color_rate): value = (1/len(color_rate)- color_rate[str(num)][self.data_long[0]])* self.quanzhong[0]/sum(self.quanzhong) value += (color_rate[str(num)][self.data_long[1]] - 1/len(color_rate)) * self.quanzhong[1]/sum(self.quanzhong) value += (color_rate[str(num)][self.data_long[2]] - 1/len(color_rate)) * self.quanzhong[2]/sum(self.quanzhong) value make_quanzhong(self): i range(1,34): self.red_qz.append([self.(i,self.red_rate),i]) i range(1,17): self.blue_qz.append([self.(i,self.blue_rate),i]) init_data(self): self.() self.() self.make_quanzhong() _str_format(self,s): a = re.compile() b = re.findall(a,s) b _find_qz(self,color_qz,num): i range(0,34): color_qz[i][1] == num: color_qz[i][0] _suiji_gl(self): sjgl = 1 x range(28,34): sjgl *= x sjgl = 1/sjgl sjgl * 1/16 gailv(self,s): lst = self._str_format(s) lst = [int(x) x lst] gl = 1 lst len(lst)>7 len(lst)<7 max(lst)="">33 min(lst)<1: none="">: x lst[:7]: gl *= (1+self._find_qz(self.red_qz,x)) gl * self._suiji_gl() caipiao_random(self): redball = sorted(random.sample(range(1,34),6)) blueball = random.sample(range(1,17),1) redball + blueball print_random(self): random_ball = self.caipiao_random() () (,random_ball[:6],,random_ball[6:7]) () print_best_number(self): () () (,sorted(list(x[1] x sorted(self.red_qz)[-6:])),,sorted(self.blue_qz)[-1][1]) () print_gl(self): (输入格式为-> \'(1,9,13,21,28,32)(14)\'')
157 c = input('请输入:')
158 if not self.gailv(c):
159 print('输入有误!')
160 return
161 print('--------------------------------------------------')
162 print(' 随机概率为:%0.10f%%'%(self._suiji_gl()*100))
163 print(' -------------------------')
164 print(' 自选概率为:%0.10f%%'%(self.gailv(c)*100))
165 print('--------------------------------------------------')
166 def print_all(shuangseqiu_obj):
167 print('''
168 |----------功能列表-------------|
169 |--1:打印中奖率最高代码---------|
170 |--2:打印随机号码---------------|
171 |--3:自助选取号码,打印中奖概率-|
172 |--q:退出-----------------------|
173 ''')
174
175 while True:
176 a = input('功能选择:')
177 if a == '1':
178 shuangseqiu_obj.print_best_number()
179 elif a == '2':
180 shuangseqiu_obj.print_random()
181 elif a == '3':
182 shuangseqiu_obj.print_gl();
183 elif a == 'q':
184 break;
185 else:
186 print('输入有误')
187 print('谢谢使用')
188
189 if __name__ == '__main__':
190 b = shuangseqiu()
191 b.init_data()
192 print_all(b)
193
194
复制代码


程序中使用双色球历史中奖号码进行分析,文件为123.txt,文件格式如下:

序列    年份    期号    日期       红1    红2    红3    红4    红5    红6    蓝球
1310    2012    2012025    2012/3/1    4    12    19    21    25    28    13   
1308    2012    2012023    2012/2/28    5    9    15    23    24    33    2   
1307    2012    2012022    2012/2/26    4    8    12    24    26    27    4   
1306    2012    2012021    2012/2/23    1    15    16    18    22    30    3   
1305    2012    2012020    2012/2/21    3    8    12    18    23    29    11   
1304    2012    2012019    2012/2/19    7    14    18    20    22    30    16   
1303    2012    2012018    2012/2/16    3    5    6    22    26    32    15   
1302    2012    2012017    2012/2/14    6    9    14    19    25    28    10   
1301    2012    2012016    2012/2/12    2    5    12    17    22    25    8   
1300    2012    2012015    2012/2/9    1    3    6    10    21    23    15   
1299    2012    2012014    2012/2/7    1    2    5    16    28    30    12   
1298    2012    2012013    2012/2/5    6    8    24    29    30    32    13   
1297    2012    2012012    2012/2/2    15    17    18    20    23    27    1   
1296    2012    2012011    2012/1/31    4    14    15    16    20    26    5   
1295    2012    2012010    2012/1/29    1    3    13    19    25    26    10   
1294    2012    2012009    2012/1/19    4    16    24    26    27    33    11   
1293    2012    2012008    2012/1/17    1    12    20    23    24    29    8   
1292    2012    2012007    2012/1/15    10    17    19    27    28    32    4   
1291    2012    2012006    2012/1/12    2    22    25    29    32    33    8   
1290    2012    2012005    2012/1/10    7    9    18    27    31    33    6   
1289    2012    2012004    2012/1/8    1    5    10    11    21    23    16   
1288    2012    2012003    2012/1/5    3    6    8    24    29    31    9   
1287    2012    2012002    2012/1/3    2    3    7    9    10    32    13   
1286    2012    2012001    2012/1/1    1    4    5    9    15    17    6   
1285    2011    2011153    2011/12/29    5    8    9    10    20    25    13   
1284    2011    2011152    2011/12/27    4    10    11    12    21    26    13   
1283    2011    2011151    2011/12/25    7    11    16    19    31    33    10   
1282    2011    2011150    2011/12/22    8    10    12    15    22    27    13   
1281    2011    2011149    2011/12/20    4    5    6    7    23    31    16   
1280    2011    2011148    2011/12/18    5    14    22    23    25    26    14   
1279    2011    2011147    2011/12/15    4    8    12    17    18    30    10   
1278    2011    2011146    2011/12/13    11    23    26    28    32    33    10   
1277    2011    2011145    2011/12/11    2    4    14    15    26    30    4   
1276    2011    2011144    2011/12/8    1    2    9    10    16    24    3   


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多