Advertisement
amigojapan

how to get 1 to 100 using dice in JS

Mar 12th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getDiceRoll() {//I tested that it generates 1 to 6 by for(i=0;i<10000;i++)if(getDiceRoll()==1) console.log("has 1");
  2.   return Math.floor(Math.random() * (6 - 1) + 1);//should be floor
  3. }
  4. //just multiply the first digit of he die  by 10 and then substract 11 to make it from 0 to 55, repeat the procedure until it is more than 50
  5. // make that A. then repeat the same procedure and make that B if be is 0 add 1, then ad A and B
  6. function Zero_to_50(){
  7.     do {
  8.         var tmp=(getDiceRoll()*10)+getDiceRoll()-11;//[0-6]*10+[0-6]-11  the reason why I substract 11 is because that is a maximum of 66 and I subtract 11 to make it from [-10 to 50]
  9.     }while(tmp<0);
  10.     //if(tmp<0) console.log("tmp <0");//this test seems to pass, never less than 0
  11.     return tmp;
  12. }
  13. function One_to_100() {
  14.     var A=Zero_to_50();
  15.     var B=Zero_to_50();
  16.     if(B==0) {
  17.         B=1;
  18.     }
  19.     var one_to_100=A+B;
  20.     return one_to_100
  21. }
  22. for(i=0;i<10000;i++){var n=One_to_100();if(!(n>=1)) console.log("value not >= 1");}
  23. for(i=0;i<10000;i++){var n=One_to_100();if(!(n<=100)) console.log("value not <=  100");}
  24.  
  25. /*
  26. sir_galahad_ad: I also devized a way for it to be impossible for the “executor”(the person who evals the program to cheat in generating a random number,   every dice roll, the player writes down the dice results and the executor writes down the secret random number, after the game is over, the player then runs the computations of the dice numbers he wrote down, and checks to see if it matches with the hidden number(which is revealed by now)
  27. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement