text: class Letto{
  
      createIntRange(start, end) {
          let intArray = [];
          for(let i=start; i<=end; i++){
              intArray.push(i);
          }
          return intArray;
      }
  
      shuffleArray(array){
          for(let i=array.length-1; i>0; i--){
              let j = Math.floor(Math.random() * (i+1));
              [array[i], array[j]] = [array[j], array[i]];
          }
          return array;
      }
  
      createRandomLetto(start, end, pick){
          let intArray = this.createIntRange(start, end);
          intArray = this.shuffleArray(intArray);
          intArray = intArray.slice(0, pick);
          return intArray;
      }
  
      checkBingo(targetSet, playerArray){
          let count = 0;
          playerArray.forEach(function(element){
              if(targetSet.has(element)){
                  count++;
              }
          });
          return count;
      }
  
  }
  
  //==========
  
  
  function roll(unique=false){
  
      //累計次數統計表
      const bingoMap = new Map([
          [0, 0],
          [1, 0],
          [2, 0],
          [3, 0],
          [4, 0],
          [5, 0]
      ]);
  
      //中獎獎金表
      const rewards = new Map([
          [0, 0],
          [1, 0],
          [2, 50],
          [3, 300],
          [4, 20000],
          [5, 8000000]
      ]);
  
      //購買彩券花費
      const lettoCost = 50;
  
      //包牌用：紀錄購買組合，判斷是否重複
      const playerSet = new Set();
  
      //==================================================
  
      //初始化class
      const letto = new Letto;
  
      //產生開獎號碼
      const targetArray = letto.createRandomLetto(start=1, end=39, pick=5);
      const targetSet = new Set(targetArray);
  
      //取得購買數量
      let quantity = document.getElementById("quantity").value;
      if(unique === true) quantity = Math.min(quantity, 575757); //包牌最大數量限制
  
      //模擬購買
      for(let i=0, playerArray, playerString; i<quantity; i++){
          while(true){
              playerArray = letto.createRandomLetto(start=1, end=39, pick=5);
              playerString = playerArray.sort().join('-');
              if(unique === true && playerSet.has(playerString)){
                  continue;
              }else{
                  playerSet.add(playerString);
                  break;
              }
          }
          const bingoCount = letto.checkBingo(targetSet, playerArray);
          bingoMap.set(bingoCount, bingoMap.get(bingoCount)+1);
      }
  
      //==================================================
  
      //網頁顯示結果
      let totalIncome = 0;
      let totalBingo = 0;
  
      //清除表格資料
      let tbody = document.getElementById("lettoTable").getElementsByTagName('tbody')[0];
      tbody.innerHTML = "";
  
      for(let [key, value] of bingoMap){
          const income = (-lettoCost + rewards.get(key)) * value;
          totalIncome += income;
          if(key>=2) totalBingo += value;
  
          lastRow = tbody.insertRow();
          lastRow.insertCell(0).innerHTML = key;
          lastRow.insertCell(1).innerHTML = value;
          lastRow.insertCell(2).innerHTML = income;
      }
  
      lastRow = tbody.insertRow();
      lastRow.insertCell(0).innerHTML = "總組合數";
      lastRow.insertCell(1).innerHTML = playerSet.size;
      lastRow.insertCell(2).innerHTML = "X";
      
  
      lastRow = tbody.insertRow();
      lastRow.insertCell(0).innerHTML = "總計";
      lastRow.insertCell(1).innerHTML = totalBingo;
      lastRow.insertCell(2).innerHTML = totalIncome;
  
  }
  