Created
June 5, 2012 15:45
-
-
Save usagi/2875850 to your computer and use it in GitHub Desktop.
バグ報告用サンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var typeTargets = new Array(//問題配列 | |
| "STRAWBERRY", "ORANGE","CHERRY","BANANA" | |
| ); | |
| function next() { | |
| var index = Math.round(Math.random() * (typeTargets.length - 1));//問題数分の乱数生成 | |
| return typeTargets[index]; //問題配列[乱数] | |
| } | |
| // ↑ここまでは | |
| // https://github.com/yorugiri015/game/blob/bb0322b7321edc90dc78c3734094fda835eba2e7/Typing/typing.html | |
| // より問題の本質に関わる部分を抜粋 | |
| // ↓シミュレーション | |
| // 出題回数を記録するカウンターを初期化 | |
| var counter = {}; | |
| for ( var t_key in typeTargets ) | |
| counter[ typeTargets[t_key] ] = 0; | |
| // シミュレーション | |
| var N = 1000 * 1000; | |
| for ( var n = 0; n < N; ++n) | |
| ++counter[next()]; | |
| // 出題確率を計算 | |
| var ratio = {}; | |
| for ( var c_key in counter ) | |
| ratio[c_key] = counter[c_key] / N; | |
| // 結果表示 | |
| for ( var c_key in counter ) | |
| console.log( | |
| c_key + ': ' + | |
| counter[c_key] + '[回] (' + | |
| (100 * ratio[c_key]).toFixed(2) + '[%])' | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果の例:
STRAWBERRY: 166622回
ORANGE: 333161回
CHERRY: 333317回
BANANA: 166900回