[removed] How To Code a Heads/Tails With Specific Probability Chance Percentage?

前端 未结 2 1958
情书的邮戳
情书的邮戳 2021-01-29 08:32

I\'ve implemented the function:

 function coinFlip() {
      return(Math.floor(Math.random()*2) === 0) ? \'Heads\' : \'Tails\';
 }

And it\'s al

2条回答
  •  走了就别回头了
    2021-01-29 08:59

    If one of three toss coin is head it doesn't mean that in 10 toss, there will be 3 heads.. Here is your code with 500 toss (just change the number)

        function coinFlip() {
              return(Math.random() < 0.3) ? 'Heads' : 'Tails'; //ofc 0.3 is 30% (3/10)
        }
    
     var howManyTimes=500;
     var countHeads=0; 
     for (var i=0; i

    "how to solve a specific percentage problem"

    You can't, this is how probability works

提交回复
热议问题