Advertisement
Awn_pastebin

myRepdigitSimulator.js

Jan 19th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*=====================================/
  2. *****************************
  3. *       myRepdigitSimulator.js    *
  4. *****************************
  5. ★コンマゾロ目をすべて(000,111,222,...,999)出すまで乱数を回すシミュレーターです★
  6.  
  7. -スクリプト作成者: Awn◆Awn//////E
  8. -スクリプト作成者(tw): https://twitter.com/Awn_tw
  9.  
  10. -諸注意:
  11.         +自由に改変して良いです。
  12.         +但し、スクリプト作成者は当スクリプトから発生する不利益に対して一切の責任を負いません。
  13.  
  14. ======================================*/
  15.  
  16.  
  17. ///////////////////////////////
  18. //
  19. //テスト回数
  20. testKaisu = 1000; // <--- 値を変えるとしたらここだけでおkです
  21. //
  22. ///////////////////////////////
  23.  
  24.  
  25. document.write("<h1>コンマゾロ目コンプリートシミュレーター</h1>");
  26. //乱数発生
  27. function getRandomInt(min, max) {
  28.   return Math.floor( Math.random() * (max - min + 1) ) + min;
  29. }
  30.  
  31. //ゾロ目が全て出揃うまで乱数を出す
  32. function myTest(){
  33.     output = [];
  34.     output2 = [];
  35.     count = 0;
  36.  
  37.     while(output.length != 10){
  38.         w = getRandomInt(0,999);
  39.         count++;
  40.         if(w % 111 == 0){
  41.             if(output.indexOf(w) == -1){
  42.                 output.push(w);
  43.                 output2.push(count);
  44.             }
  45.         }
  46.     }
  47. return count;
  48. }
  49.  
  50. //テストを"testKaisu"回実行する
  51. res = [];
  52. for(i = 0; i < testKaisu; i++){
  53.     mess = [];
  54.     console.log(i+1 + "回目のテスト");
  55.     document.write(i+1 + "回目のテスト" + "<br>")
  56.  
  57.     c = myTest();
  58.  
  59.     console.log(" " + c + "レス目でコンプリートしますた(・∀・)");
  60.     document.write(" " + c + "レス目でコンプリートしますた(・∀・)" + "<br>")
  61.  
  62.  
  63.         for(j = 0;j < 10; j++){
  64.             mess.push(output2[j] + "レス目:" + output[j] + " ");
  65.         }
  66.     document.write("<small>  内訳:" + mess + "</small><br>");
  67.     res.push(c);   
  68. }
  69.  
  70.  
  71. //平均の算出
  72. sum = 0;
  73. for(i = 0; i < res.length; i++){
  74.     sum += res[i];
  75. }
  76. avr = sum/res.length;
  77.  
  78.  
  79. //メッセージ設定
  80. mes = testKaisu + "回実行した結果、" + "平均レス数は" + Math.floor(avr) + "回ですた(・∀・)";
  81.  
  82. console.log(mes);
  83. document.write("--------------------<br>");
  84. document.write("<h2>" + mes + "</h2><br>");
  85.  
  86. //End of Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement