Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Nレスでコンマゾロ目の種類がどれくらい出るかその割合をシミュレートする
- *Note that:
- ブラウザへの負荷(?)を低減するべく、計算結果はconsole.log()上にのみ出力します
- *出力例
- ------------------------------
- 【テスト概要】
- テスト回数: 10,000,000回
- 1テスト中のレス数: 1000レス
- 【テスト結果】
- ゾロ目の種類の数
- 0個,1個,2個,3個,4個,5個,6個,7個,8個,9個,10個
- 出現回数
- 474,7453,58945,271217,826788,1714867,2462263,2414209,1552369,591533,99882
- 出現頻度
- 0.004%,0.074%,0.589%,2.712%,8.267%,17.148%,24.622%,24.142%,15.523%,5.915%,0.998%
- ------------------------------
- */
- ///////////////////////////////
- //
- //パラメータ
- //
- //テスト回数
- testKaisu = 10000000;
- //1テスト中のレス数
- N = 1000;
- //
- //
- ///////////////////////////////
- //乱数発生用の関数
- function getRandomInt(min, max) {
- return Math.floor( Math.random() * (max - min + 1) ) + min;
- }
- //コンマゾロ目の種類が揃った数を保持するための変数
- bunpu = [0,0,0,0,0,0,0,0,0,0,0];
- //シミュレーターの作成
- function mySimulator(){
- output = [];
- // output2 = [];
- for(i = 0; i < N; i++){
- //乱数発生
- w = getRandomInt(0,999);
- //コンマがゾロ目の時
- if(w % 111 == 0){
- if(output.indexOf(w) == -1){
- output.push(w);
- // output2.push(i);
- }
- }
- }
- // console.log(output.length);
- return output.length;
- }
- //シミュレーションを"testKaisu"回実行する
- for(j = 0; j < testKaisu; j++){
- // console.log((j + 1) + "回目のテストです");
- //シミュレーターの実行、戻り値を得る
- r = mySimulator();
- // console.log(r);
- //ゾロ目が何種類揃ったか、その分布を取る
- bunpu[r] += 1;
- //結果確認
- /*
- console.log(output.join(","));
- console.log(output2.join(","));
- */
- }
- //【出力】見出し
- console.log(" 【テスト概要】 ");
- console.log("テスト回数: " + String(testKaisu).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + "回");
- console.log("1テスト中のレス数: " + N + "レス");
- console.log(" 【テスト結果】 ");
- //【出力】結果
- console.log("ゾロ目の種類の数");
- console.log("0個,1個,2個,3個,4個,5個,6個,7個,8個,9個,10個");
- console.log("出現回数");
- console.log(bunpu.join(","));
- console.log("出現頻度");
- console.log(( bunpu.map(function(x) {return Math.floor(100 * 1000 * (x / testKaisu)) / 1000 + "%" } ) ).join(","));//小数点第3桁まで出す
- //End Of Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement