イカサマビンゴ2.1

イカサマビンゴ2.1

イカサマビンゴ2をアップデートし、イカサマビンゴ2.1を作りました。
ソース見られても怪しまれないバージョン。

こちら。
http://green.ribbon.to/~mhirai/bingo2_1.html

前回のイカサマビンゴ2の記事はこちら。
http://d.hatena.ne.jp/hirai428/20140120

ポイントはMath.randomを書き換えてることと、イカサマコードは全てjQueryに記載することで盲点を突いている(つもり)こと。
ので、jQueryの中見られたらアウト。
jQueryもここでは見やすく書いていますが、変数名難読化+改行消去とかすればjQueryの中見られてももしかしたらバレないかも?
あっ例によって警告が出るのでjQueryの新しいやつを使うか、警告の目立たないブラウザを使うのがいいと思います。

Math.randomの戻り値を(numReserve - 1) / MAX_NUM;
としていたのだが、

ChromeにてnumReserveが56の場合
(numReserve - 1) / MAX_NUM
= (56 - 1) / 75
= 0.7333333333333333

となってしまい、この場合抽選結果は
Math.floor(Math.random() * MAX_NUM) + 1;
= Math.floor(0.7333333333333333*75 + 1)
= 55
となってしまったので仕方なく

ret = (numReserve - 1) / MAX_NUM + 0.0001;

としました。もう少しうまいやり方はないものかね・・・
numReserveが41の場合とかはちゃんと
Math.floor(Math.random() * MAX_NUM) + 1;
= Math.floor(0.5333333333333333*75 + 1)
= 41

となるし、アラートで比較すると以下のようになるのでなんか丸め方に差異があったりするのかね。
有効数値カナーとも思ったけど、それだけではなさそう?
学力ないのでわかりません。

alert(0.7333333333333333*75);
 →54.99999999999999
alert(0.5333333333333333*75);
 →40
alert(0.533333333333333*75);
 →39.99999999999997
alert(0.73333333333333333*75);
 →54.99999999999999
alert(0.3333333333333333*75);
 →25
alert(1.1333333333333333*75);
 →85

脱線したが、以下ソイソース。

【HTML部】


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
td{
font-weight : bold;
}
td.notyet{
background-color : #AAAAAA;
}
td.yet{
background-color : #FFFF00;
}
</style>
<script type="text/javascript" src="./jquery-1.10.2.squid.js"></script>
<script type="text/javascript">

var MAX_NUM = 75;
var resultArray = [false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false];

var output = "";

function choose(){

if(!checkFinish()){
alert("もう終わってます。");
return;
}
var result = null;
output = "";

if(result == null){
do{
result = Math.floor(Math.random() * MAX_NUM) + 1;

var checkMessage = checkDuplicate(result);
if(!checkDuplicate(result)){
output += "重複しているので再抽選します。<br />";
}else{
break;
}
}while(true);
}
resultArray[result - 1] = true;

$("#td_" + result).attr("class", "yet");
$("#OUTPUT").html(output);
}

function checkFinish(){
var finish = true;
for(var i = 0; i < resultArray.length; i++){
if(!resultArray[i]){
finish = false;
break;
}
}
return !finish;
}

function checkDuplicate(result){
return !resultArray[result - 1];
}

</script>
</head>
<body>
<table border="1">
<tbody>
<tr>
<td id="td_1" class="notyet">1</td>
<td id="td_2" class="notyet">2</td>
<td id="td_3" class="notyet">3</td>
<td id="td_4" class="notyet">4</td>
<td id="td_5" class="notyet">5</td>
<td id="td_6" class="notyet">6</td>
<td id="td_7" class="notyet">7</td>
<td id="td_8" class="notyet">8</td>
<td id="td_9" class="notyet">9</td>
<td id="td_10" class="notyet">10</td>
<td id="td_11" class="notyet">11</td>
<td id="td_12" class="notyet">12</td>
<td id="td_13" class="notyet">13</td>
<td id="td_14" class="notyet">14</td>
<td id="td_15" class="notyet">15</td>
</tr>
<tr>
<td id="td_16" class="notyet">16</td>
<td id="td_17" class="notyet">17</td>
<td id="td_18" class="notyet">18</td>
<td id="td_19" class="notyet">19</td>
<td id="td_20" class="notyet">20</td>
<td id="td_21" class="notyet">21</td>
<td id="td_22" class="notyet">22</td>
<td id="td_23" class="notyet">23</td>
<td id="td_24" class="notyet">24</td>
<td id="td_25" class="notyet">25</td>
<td id="td_26" class="notyet">26</td>
<td id="td_27" class="notyet">27</td>
<td id="td_28" class="notyet">28</td>
<td id="td_29" class="notyet">29</td>
<td id="td_30" class="notyet">30</td>
</tr>
<tr>
<td id="td_31" class="notyet">31</td>
<td id="td_32" class="notyet">32</td>
<td id="td_33" class="notyet">33</td>
<td id="td_34" class="notyet">34</td>
<td id="td_35" class="notyet">35</td>
<td id="td_36" class="notyet">36</td>
<td id="td_37" class="notyet">37</td>
<td id="td_38" class="notyet">38</td>
<td id="td_39" class="notyet">39</td>
<td id="td_40" class="notyet">40</td>
<td id="td_41" class="notyet">41</td>
<td id="td_42" class="notyet">42</td>
<td id="td_43" class="notyet">43</td>
<td id="td_44" class="notyet">44</td>
<td id="td_45" class="notyet">45</td>
</tr>
<tr>
<td id="td_46" class="notyet">46</td>
<td id="td_47" class="notyet">47</td>
<td id="td_48" class="notyet">48</td>
<td id="td_49" class="notyet">49</td>
<td id="td_50" class="notyet">50</td>
<td id="td_51" class="notyet">51</td>
<td id="td_52" class="notyet">52</td>
<td id="td_53" class="notyet">53</td>
<td id="td_54" class="notyet">54</td>
<td id="td_55" class="notyet">55</td>
<td id="td_56" class="notyet">56</td>
<td id="td_57" class="notyet">57</td>
<td id="td_58" class="notyet">58</td>
<td id="td_59" class="notyet">59</td>
<td id="td_60" class="notyet">60</td>
</tr>
<tr>
<td id="td_61" class="notyet">61</td>
<td id="td_62" class="notyet">62</td>
<td id="td_63" class="notyet">63</td>
<td id="td_64" class="notyet">64</td>
<td id="td_65" class="notyet">65</td>
<td id="td_66" class="notyet">66</td>
<td id="td_67" class="notyet">67</td>
<td id="td_68" class="notyet">68</td>
<td id="td_69" class="notyet">69</td>
<td id="td_70" class="notyet">70</td>
<td id="td_71" class="notyet">71</td>
<td id="td_72" class="notyet">72</td>
<td id="td_73" class="notyet">73</td>
<td id="td_74" class="notyet">74</td>
<td id="td_75" class="notyet">75</td>
</tr>
</tbody>
</table>

あらかじめセルをクリックしておくことで、<br />
下のボタンを押した際にクリックしたセルの数値が抽選されます。<br />
いちいち「event.returnValue is deprecated.」とか出るのはjQueryのバグらしいです。<br />
修正版は既にあるみたいですが、ベータ版のようなのでここでは正式リリース版を使用してます。<br />

<input type="button" value="抽選する" onclick="choose();">

<div id="OUTPUT"></div>
</body>
</html>

jQuery追記部】

Math.orgRandom = Math.random;
var numReserve = null;

Math.random = function(){
if(numReserve == null){
ret = Math.orgRandom();
output += "ランダムな抽選結果を出します:" + ret + "<br />";
}else{
ret = (numReserve - 1) / MAX_NUM + 0.0001;
numReserve = null;
output += "セルクリックにより予約されている番号が出るようランダム値を返します:" + ret + "<br />→Math.floor(" + ret + "*" + MAX_NUM + " + 1) = " + eval(Math.floor(ret * MAX_NUM) + 1) + "<br />";
}
return ret;
}

function reserve(ev){
try{
numReserve = parseInt(ev.target.id.slice(3));
}catch(e){
numReserve = null;
}
}

$(window).load(
function(){
$("td.notyet").click(reserve);
}
);