zoukankan      html  css  js  c++  java
  • 都来中大奖啦~双色球随机算法!

    双色球现在越来越火了,但是每次选号,有的人看线,有的人只买一注固定的,但是我觉得,还是随机的比较好。

    具体哪个概率高呢 ?这个还真没有统计过,期待大家都中奖哦

    双色球的内幕?我想是没有的吧。。。

    好了,废话不多说,大家看代码吧~试试能不能中奖~~~~

    这个需要引用 jquery库 大家自备吧

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <link type="image/x-icon" href="http://t3.baidu.com/it/u=3805438121,3902039635&fm=21&gp=0.jpg" rel="SHORTCUT ICON">
            <title>双色球随机号</title>
        </head>
        
        <style type="text/css">
        .show_body{margin: 0 auto; width: 800px; height:900px; background-color:#F5FFFA; margin-top: 20px;}
        .show_rand_num{position: relative;top: 40px; left: 80px; height: 80px; width: 550px; background-color:#F0FFF0; float: left;}
        .show_history{position: relative;top: 80px; left: 80px; height: 480px; width: 600px; background-color:#F0F8FF; float: left;overflow: auto;}
        .show_best{position: relative;top: 120px; left: 80px; height: 80px; width: 550px; background-color:#EEE8AA; float: left; }
        .show_history_num{position: relative;top: 0px; left: 0px; height: 80px; width: 550px; margin-top:0px; float: left;}
        .blueNum{ width: 60px; height: 60px; border: none;background-color: #227700;border-radius:40px; margin-top: 10px;margin-left: 30px; color: white;font: '宋体';font-size: 50px;text-align: center;}
        .redNum{ width: 60px; height: 60px; border: none;background-color: #A42D00;border-radius:40px; margin-top: 10px;margin-left: 10px; color: white;font: '宋体';font-size: 50px;text-align: center;}
        </style>
        <script type="text/javascript" src="jquery-1.7.1.min.js"> </script>
        <script type="text/javascript">
            // 自动运行中标志
            var autoRuning=false;
            $(function(){
                // 生成6+1个文本框输入
                apendRandNum();
                stopRandNum(0);
                // 单次
                var runFlag=true;
                var randInterval=0;
                var runAutoFlag=true;
                $("#buttonRandNum").click(function(){
                    // 菜单制域
                    if(!runAutoFlag){
                        return;
                    }
                    if(runFlag){
                        runFlag=false;
                        randInterval=biginRandNum();
                        $(this).val("停止");
                    }else{
                        runFlag=true;
                        stopRandNum(randInterval);
                        dataAnalysis();
                        $(this).val("开始");
                    }        
                });
                // 50次自动生成
                $("#buttonRandNumAuto").click(function(){
                    // 菜单制域
                    if(!runFlag){
                        return;
                    }
                    if(runAutoFlag){
                        runAutoFlag=false;
                        autoRuning=true;
                        randInterval=biginRandNum();
                        stopAfter2s(1);
                        $(this).val("停止");
                    }else{
                        runAutoFlag=true;
                        autoRuning=false;
                        stopRandNum(randInterval);
                        dataAnalysis();
                        $(this).val("开始");
                    }    
                });
            });
            
            // 1s后暂停
            function stopAfter2s(times){
                if(autoRuning){
                    if(!times){
                        dataAnalysis();    
                    }
                    
                    setTimeout(stopAfter2s,1000);
                }
    
            }
            
            
            function dataAnalysis(){
                // 红球排序处理
                var redNum=$(".show_rand_num").find(".redNum");
                
                for(var i=0;i<redNum.length;i++){
                    for(var j = redNum.length-1; j>i ;j-- ){
                        if(parseInt($(redNum[j]).val())<parseInt($(redNum[i]).val())){
                            var temp=redNum[i];
                            redNum[i]=redNum[j];
                            redNum[j]=temp;
                        }
                    }    
                }
                redNum.each(function(){
                    $(this).remove();
                });
                for(var i=0;i<redNum.length;i++){
                    $(".show_rand_num").find(".blueNum").before($(redNum[i]));
                }
            
                // 移到历史记录区
                $(".show_rand_num").clone().removeClass().addClass("show_history_num").prependTo($(".show_history"));
                
                // 生成最佳号码
                // 清空最佳显示号
                $(".show_best").empty();
                for(var i=0;i<7;i++){
                    // 一列数组
                    var oneLie=[];
                    $(".show_history").find(".show_history_num").each(function(){
                        oneLie.push($(this).find("input").eq(i).val());
                    });
                    // 找寻数组中最多的数字
                    // 每个数字出现次数
                    var NumTimes=[];
                    for(var j=0;j<oneLie.length;j++){
                        if(!NumTimes[oneLie[j]]){
                            NumTimes[oneLie[j]]=1;    
                        }else{
                            NumTimes[oneLie[j]]=NumTimes[oneLie[j]]+1;
                        }            
                    }
                    // 寻找出现次数最多的,且次数至少大于1的
                    var bestNum=0;
                    var bestNumTimes=0;
                    for(key in NumTimes){
                        if(NumTimes[key]>1&&NumTimes[key]>=bestNumTimes){
                            bestNum=key;
                            bestNumTimes=NumTimes[key];
                        }
                    }
    
                    // 生成最佳号显示框
                    if(i==6){
                        $(".show_best").append($('<input type="text" class="blueNum" value="'+bestNum+'"/>'));    
                    }else{
                        $(".show_best").append($('<input type="text" class="redNum" value="'+bestNum+'"/>'));
                    }
    
                }
            }
            
            function stopRandNum(interval){
                // 暂停随机
                clearInterval(interval);
            
            }
            
            function biginRandNum(){
                return setInterval(apendRandNum,10);
            }
            
            function apendRandNum(){
                $(".show_rand_num").empty();
                var exsArr=[];
                for(var i=0;i<6;i++){
                    var createNode=createRandShowNum(1,33,'redNum',exsArr);
                    exsArr.push($(createNode).val());
                    $(".show_rand_num").append(createNode);
                }
                $(".show_rand_num").append(createRandShowNum(1,16,'blueNum'));
            }
            
            function createRandShowNum(fromValue,toValue,className,exsArr){
                var exsitFlag=false;
                var cont=toValue-fromValue;
                var randValue=fromValue+Math.round(cont*Math.random());
                
                if(exsArr){
                    for(var i=0;i<exsArr.length;i++){
                        if(randValue==exsArr[i]){
                            exsitFlag=true;
                            break;
                        }
                    }
                }
                
                // 如果存在相同的,从新随机
                while(exsitFlag){
                    exsitFlag=false;
                    randValue=fromValue+Math.round(cont*Math.random());
                    for(var i=0;i<exsArr.length;i++){
                        if(randValue==exsArr[i]){
                            exsitFlag=true;
                            break;
                        }
                    }
                }
                return $('<input type="text" class="'+className+'" value="'+randValue+'"/>');
                
            }
            
        </script>
            
        <body>
    
        
        <div class="show_body">
            <!-- 随机结果展现区 -->
            <div class="show_rand_num">
            </div>
            
            <!-- 菜单区 -->
            <div style=" 150px;height: 40px;position:relative; top: 60px;right: 10px;float: right;" >
                <input type="button" id="buttonRandNum" value="开始" style=" 70px;height: 40px;font-size: 30px;cursor: pointer;" />
                <input type="button" id="buttonRandNumAuto" value="自动" style=" 70px;height: 40px;font-size: 30px;cursor: pointer;" />
            </div>
            
            <!-- 历史记录展示区 -->
            <div class="show_history">
            </div>
            
            <!-- 最佳号码 -->
            <div class="show_best">
    
            </div>
            
            
            </div>
        
        </body>    
            
    
    </html>
  • 相关阅读:
    将vue文件script代码抽取到单独的js文件
    git pull 提示错误:Your local changes to the following files would be overwritten by merge
    vue和uniapp 配置项目基础路径
    XAMPP Access forbidden! Access to the requested directory is only available from the local network.
    postman与newman集成
    postman生成代码段
    Curl命令
    POST方法的Content-type类型
    Selenium Grid 并行的Web测试
    pytorch转ONNX以及TnesorRT的坑
  • 原文地址:https://www.cnblogs.com/ranzige/p/shuangseqiu_html.html
Copyright © 2011-2022 走看看