十行代码写个彩票随机生成器(双色球+大乐透)

1,614次阅读
没有评论

规则

双色球(红球33选6,蓝球16选1)
大乐透(红球35选5,蓝球12选2)

生成随机数

  1. 生成的数要不重复且在规则范围内
  2. for循环+do while+boolean去重
    (当然这样的效率很低,可是暂且够用就行了,如果想知道优化版怎么做的话,请移步此博客:)

代码

客户端代码

public class DoubleChomper {
    //双色球红球范围(所有期望值+1)
   public static int redRange = 34;
    //双色球红球个数
    public static int redFrequency = 6;
    //双色球蓝球范围
    public static int blueRange = 17;
    //双色球蓝球个数
    public static int blueFrequency = 1;
    //大乐透红球范围
    public static int leTouRedRange =36;
    //大乐透红球个数
    public static int leTouRedFrequency = 5;
    //大乐透蓝球范围
    public static int leTouBlueRange = 13;
    //大乐透蓝球范围
    public static int leTouBlueFrequency = 2;

    public static void main(String[] args) {
        getResult(10,10);
    }
复制代码

核心代码

	/**
     * 彩票选球
     * @param range 选球范围
     * @param number 选球个数
     * @return
     */
    private static List getTheBall(int range, int number){
        //定义接收数组
        List red_list =new ArrayList(6);
        Random rand = new Random();
        boolean[] bool = new boolean[range];
        int randInt = 0;
        //循环生成随机数去重后添加到接收数组中
        for(int i = 0; i < number ; i++) {
            do {
                randInt = rand.nextInt(range-1)+1;
            } while (bool[randInt]);
            bool[randInt] = true;
            red_list.add(randInt);
        }
        //结果集排序
        red_list.sort(Comparator.naturalOrder());
        return red_list;
    }
复制代码

打印

	/**
     * 循环打印结果
     * @param doubleColorNum 双色球生成号码注数
     * @param leTouNum 大乐透生成号码注数
     */
    public static void getResult(int doubleColorNum , int leTouNum ){
        System.out.println("双色球机选结果");
        for (int i = 0; i <doubleColorNum ; i++) {
            List red = getTheBall(redRange,redFrequency);
            List blue = getTheBall(blueRange,blueFrequency);
            System.out.println("红球: "+red+";蓝球:  "+blue);
        }
        System.out.println("大乐透机选结果");
        for (int i = 0; i <leTouNum ; i++) {
            List red = getTheBall(leTouRedRange,leTouRedFrequency);
            List blue = getTheBall(leTouBlueRange,leTouBlueFrequency);
            System.out.println("红球:"+red+";   蓝球:" + blue);
        }
    }

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 4 月
 12
3456789
10111213141516
17181920212223
24252627282930
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开 Jay 2026-01-08 20:18:...
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享 衡宇 2026-01-08 20:...
开源“裸考”真实世界,国产具身智能基座模型拿下全球第二!

开源“裸考”真实世界,国产具身智能基座模型拿下全球第二!

开源“裸考”真实世界,国产具身智能基座模型拿下全球第二! 西风 2026-01-08 19:02:20 来源:...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
8块钱跑通一次强化学习全流程,潞晨云重塑微调赛道:1名算法工程师=1支Infra团队

8块钱跑通一次强化学习全流程,潞晨云重塑微调赛道:1名算法工程师=1支Infra团队

8块钱跑通一次强化学习全流程,潞晨云重塑微调赛道:1名算法工程师=1支Infra团队 思邈 2026-01-0...
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开 Jay 2026-01-08 20:18:...
训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享

训具身模型遇到的很多问题,在数据采集时就已经注定了丨鹿明联席CTO丁琰分享 衡宇 2026-01-08 20:...