简介

从技术层面来讲,无论是哪种语言都是可以实现这个功能的,同样的无论是福彩还是体彩,只要你了解其中游戏规则,那么利用代码实现机选是完全没有问题的。本文仅使用两种语言来实现:ShellJavaScript

注:本文仅以 双色球 作为案例进行演示。

  • Shell 实现由于Shell 代码会被CDN过滤拦截,所以贴图

2021-06-19T07:47:23.png
动画.gif

  • JavaScript 实现
  1. JavaScript 代码只是方法实现,展示需要HTML来处理;
  2. 所以需要分两部分,即JavaScript和HTML。

JavaScript 代码

function jxuan(n){
    if (n.replace(/\s*/g,"").length!=0){
        // 获取显示器分辨率
        var c_width = Math.floor(window.screen.width*0.3);
        var c_height = Math.floor(window.screen.height*0.4);
        // 数组洗牌法
        function shuffle (array) {
             let currentIndex = array.length;
             let temporaryValue, randomIndex;

             // While there remain elements to shuffle...
             while (0 !== currentIndex) {
                 // Pick a remaining element...
                 randomIndex = Math.floor(Math.random() * currentIndex);
                 currentIndex -= 1;

                 // And swap it with the current element.
                 temporaryValue = array[currentIndex];
                 array[currentIndex] = array[randomIndex];
                 array[randomIndex] = temporaryValue;
             }
             return array;
         }
         // 福彩双色球
         var new_FC = new Array();
         for(var i=0;i<n;i++){
         var arr_fcRed = (['2','32','1','12','3','20','14','27','31','19','18','29','15','30','8','6','11','21','25','26','5','9','7','33','22','13','28','4','24','16','23','10','17']);
         // 随机生成 红球数组
          var new_arr_fcRed = shuffle([...arr_fcRed]);
          var arr_newFCred = new Array();
          for (var fcLenth=0;fcLenth<6;fcLenth++){
               // 随机取出 6 个 红球,且小于 10 的前面补 0
               var rn = Math.floor(Math.random()*new_arr_fcRed.length);
               arr_newFCred[fcLenth] = new_arr_fcRed[rn] < 10 ? 0+new_arr_fcRed[rn] : new_arr_fcRed[rn];
               // 删除以取出的红球,防止重复取球
               new_arr_fcRed.splice(rn,1);
         }

         // 排序红球
         var fcRed = arr_newFCred.sort(function(a,b){return a-b});

         // 随机生成 1 篮球,且小于 10 的前面补 0
         var new_fcBlue0 = Math.floor(Math.random()*16+1).toString();
         var new_fcBlue = new_fcBlue0 < 10 ? 0+new_fcBlue0:new_fcBlue0;
          // 彩票注数 数组 new_FC
         if ((i+1)<10) {
               var snum = "00" + (i+1);
          } else if(9<(i+1) && (i+1)<100){
               var snum = "0" + (i+1);
          } else {
               var snum = (i+1);
          }
          new_FC[i] = "第 "+snum+" 注: <font color=\"red\">"+fcRed.join(" ")+"</font> + <font color=\"blue\">"+new_fcBlue+"</font><hr />";
        }
    // 打印出生成的彩票
        w=window.open("","","width="+c_width+",height="+c_height+",toolbar=no,resizable=0,location=no,left=500,top=200");
        w.document.write("公益福彩 理性购彩 中奖随缘 切莫狂购 <hr />");
        w.document.write(new_FC.join(""));
        w.document.write("<a style=\"margin-left:50%;margin-top:50%\" href=\"https://jian.deyun.fun\">简静导航 安静无弹窗</a>");
    } else {
        lert("你和大奖之间就差一个注数\r\n请输入注数( 仅接受正整数 )");
    }
}

HTML 代码

<input style="margin-top: 15%;margin-left: 20%;height: 30px;outline-color: blue;text-align: center;" id="jxnum" placeholder="请输入机选注数">
<button style="height: 36px;" onclick="jxuan(jxnum.value)">机选一下</button>

后记

如果加上 switch 语句,就可以做如大乐透、3D等,当然其中规则就需要去彩票官网了解,然后在用JavaScript实现。

最后附上博主的源代码,由于博主不是程序员出身,所以代码写的烂大街,敬请各位大佬海涵,如果有好的建议可以在评论区进行留言。

提取码:dyun
Shell源码
JavaScript源码(完整版)

「 希望熬过一切,星光璀璨 」

流年小站,感谢有您的支持

「 道路坎坷,感谢有您 ---来自 anYun 的感谢 」

使用微信扫描二维码完成支付

2021-06-21
已阅:15730 人/次

 
 
 
分享是一种美德 x
打开微信,右上角的"+"选择"扫一扫"
使用“扫一扫”将博文分享至朋友圈吧

本文由 anYun 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。
我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3oibnoh9lo6cs

还不快抢沙发

添加新评论

Myssl安全认证