自己写程序产生彩票号码(彩民注意啊,挺实用的,省的自己想号码)

这是一个Java程序,用于生成大乐透和双色球的随机彩票号码。用户可以选择彩票类型并输入购买注数,程序会根据选择生成相应数量的彩票组合,并提示用户支付相应的费用。代码使用了Random类和Scanner类进行随机数生成和用户输入处理。

 

import java.util.Random;

import java.util.Scanner;

 

/**

 * 

 * @author David M.

 * 

 */

public class Homework_Lottery {

public static void main(String[] args) {

while (true) {

System.out.println("请输入彩票类型:1、大乐透 2、双色球.exit、退出");

Scanner sca = new Scanner(System.in);

String input = sca.next();

if (input.equals("1")) {

System.out.println("你选择了大乐透,您要几注?每注两元");

 

Random ran = new Random();

Scanner sca1 = new Scanner(System.in);

int Amount = sca1.nextInt();

System.out.println("彩票生成中……");

System.out.println("前区                                后区 ");

for (int i = 0; i < Amount; i++) {

for (int j = 0; j < 5; j++) {

int rst = ran.nextInt(32 + 1);

if (rst < 10) {

System.out.print("0" + rst);

System.out.print(" ");

} else {

System.out.print(+rst);

System.out.print(" ");

}

}

System.out.print("  + ");

Random ran1 = new Random();

int rst1 = ran1.nextInt(12 + 1);

if (rst1 < 10) {

System.out.println("0" + rst1);

} else {

System.out.println(rst1);

}

}

System.out.println("打印完成请付费RMB " + Amount * 2 + "元");

}else if(input.equals("2")){

System.out.println("你选择了双色球,您要几注?每注2元");

Scanner sca2 = new Scanner(System.in);

int Amount1 = sca2.nextInt();

System.out.println("彩票生成中……");

System.out.println("前区                          后区 ");

Random ran3 = new Random();

for (int i = 0; i < Amount1; i++) {

for (int j = 0; j < 5; j++) {

int rst = ran3.nextInt(33 + 1);

if (rst < 10) {

System.out.print("0" + rst);

System.out.print(" ");

} else {

System.out.print(+rst);

System.out.print(" ");

}

}

System.out.print("  + ");

Random ran1 = new Random();

int rst1 = ran1.nextInt(16 + 1);

if (rst1 < 10) {

System.out.println("0" + rst1);

} else {

System.out.println(rst1);

}

 

}

System.out.println("打印完成请付费RMB " + Amount1 * 2 + "元");

}else if(input.equals("exit")){

System.out.println("您已退出本系统!再见!");

return;

}else 

System.out.println("输入有误重新输入");

}

 

}

 

}

运行下彩票就出来啦,说不定命中五百万大奖:

 

 

 

### ### 数据准备与清洗 在进行彩票号码的热度和冷门分析前,首先需要获取历史开奖数据。可以通过网络爬虫技术从官方或第三方彩票网站抓取数据,并将结果保存为结构化格式(如 CSV 或 JSON)[^1]。以下是一个使用 `requests` 和 `BeautifulSoup` 抓取网页数据的示例: ```python import requests from bs4 import BeautifulSoup import pandas as pd url = "https://example.com/lottery/history" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # 假设开奖数据表格位于 class="lottery-table" 的 table 中 table = soup.find('table', {'class': 'lottery-table'}) rows = table.find_all('tr')[1:] # 跳过表头 data = [] for row in rows: cols = row.find_all('td') date = cols[0].text.strip() red_balls = cols[1].text.strip().split() blue_ball = cols[2].text.strip() data.append([date, red_balls, blue_ball]) df = pd.DataFrame(data, columns=['日期', '红球', '蓝球']) df.to_csv("dlt_history.csv", index=False) ``` ### ### 热号与冷号统计方法 热号是指在一段时间内出现频率较高的号码,而冷号则是长时间未出现的号码。可以使用 `pandas` 和 `collections.Counter` 对红球和蓝球分别进行频率统计[^2]。 ```python import pandas as pd from collections import Counter df = pd.read_csv("dlt_history.csv") # 提取所有红球号码并统计频率 all_red_balls = [ball for sublist in df['红球'].str.split() for ball in sublist] red_counter = Counter(all_red_balls) # 提取所有蓝球号码并统计频率 all_blue_balls = df['蓝球'].tolist() blue_counter = Counter(all_blue_balls) # 输出前10个热号 print("红球热号 Top 10:") print(red_counter.most_common(10)) print("\n蓝球热号 Top 5:") print(blue_counter.most_common(5)) ``` 为了识别冷号,可以设定一个时间窗口(例如最近30期),统计哪些号码在此期间未出现: ```python # 获取最近30期红球号码 recent_red_balls = [ball for sublist in df.head(30)['红球'].str.split() for ball in sublist] # 找出未出现在最近30期的红球 cold_red_balls = [num for num in range(1, 36) if str(num) not in recent_red_balls] print("红球冷号(最近30期未出现):") print(cold_red_balls) ``` ### ### 可视化展示分析结果 借助 `matplotlib` 和 `seaborn` 可以将上述统计结果可视化,生成柱状图、热力图等图表[^2]。 ```python import matplotlib.pyplot as plt import seaborn as sns # 将红球频率转换为 DataFrame red_freq_df = pd.DataFrame(list(red_counter.items()), columns=['号码', '出现次数']) plt.figure(figsize=(14, 6)) sns.barplot(x='号码', y='出现次数', data=red_freq_df.sort_values(by='号码')) plt.title('红球号码出现频率统计') plt.xlabel('红球号码') plt.ylabel('出现次数') plt.grid(axis='y', linestyle='--', alpha=0.7) plt.show() ``` 此外,还可以绘制热力图来展示号码分布情况: ```python import numpy as np # 创建红球频率矩阵(5x7) freq_matrix = np.zeros((5, 7), dtype=int) for i in range(5): for j in range(7): num = i * 7 + j + 1 freq_matrix[i, j] = red_counter.get(str(num), 0) plt.figure(figsize=(8, 6)) sns.heatmap(freq_matrix, annot=True, fmt="d", cmap="YlGnBu", xticklabels=[], yticklabels=[]) plt.title('红球号码频率热力图') plt.show() ``` ### ### 分析结论与应用建议 通过上述分析,可以直观地看出哪些号码属于“高频”或“低频”,从而辅助制定选号策略。尽管彩票本质上是随机事件,但部分彩民倾向于选择近期出现频率较高的号码以提高心理预期[^4]。因此,该分析可作为购彩决策的参考依据之一。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值