最近在买双色球,听说谣言头奖中奖号码是这一期所有号码组合中注数最少的一个,基于大部分人都是机选买彩票,所以写了代码如下模拟彩票抽奖结果。
图个乐子,早上上班跑起来,下班看下结果再去买,哈哈
代码如下

<template>
  <div class="detail-page-box">
    <span> {{ count }} </span>
    <button @click="alertResult">点我停止,并计算</button>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Watch, Prop } from "vue-property-decorator";
let timer: any;
@Component({
  components: {

  },
})
export default class CardItem extends Vue {
  count: number = 0;
  allList: any = {};
  guess() {
    this.count++;
    let str = "";
    let redNumEdList: any = [];
    let blueNum:number=0;
    for (let i = 0; i < 7; i++) {
      if (i < 6) {
        let randomNum:any = Math.floor(Math.random() * 32 + 1);
        while (redNumEdList.includes(randomNum)) {
          randomNum = Math.floor(Math.random() * 32 + 1);
        }
        redNumEdList.push(randomNum);
      } else {
        let randomNum = Math.floor(Math.random() * 15 + 1);
        blueNum=randomNum;
      }
    }
    redNumEdList.sort((a:number,b:number)=>{
        return a-b
    })
    str=redNumEdList.join("  ")
    if(blueNum<10){
        str+='--- '+'0'+blueNum
    }else{
        str+='--- '+blueNum
    }
    if (!this.allList[str]) {
      this.allList[str] = 1;
    } else {
      this.allList[str]++;
    }
  }
  alertResult() {
    let minCombination: any = "";
    let minNum: number = 0;
    clearInterval(timer);
    Object.keys(this.allList).forEach((item, index) => {
      if (index === 0) {
        minNum = this.allList[item];
        minCombination = item;
      } else {
        if (minNum > this.allList[item]) {
          minNum = this.allList[item];
          minCombination = item;
        }
      }
    });
    alert(`最小注数为:` + minNum + `号码组合为:` + minCombination);
  }
  created() {
    timer = setInterval(this.guess, 20);
  }
}
</script>
<style lang="less" scoped>
.detail-page-box {
  text-align: center;
  line-height: 100px;
}
</style>

效果图比较简陋如下
image.png

以及点击结果后图片如下,最后一个号码为蓝球,前六个为红球
image.png


贺贺贺贺
3 声望0 粉丝

分享生活中的快乐技术