문제

I have a function that I want to use to demonstrate flipping a coin 100 times:

function simulateFlips(n, pHeads){
   var head_count = 0; 
   var H; 
   for(var i=0; i < n; i++){
      H = 0; 
      if (Math.random() < pHeads){
        H = 1;
      } 
   head_count += H; 
   }
   return head_count; 
 }

However, it looks like the standard Google App Behavior is to "memoize" custom functions that are called with exactly the same inputs, which is not what you want for this kind of demo:

Screenshot from Google Spreadsheet I know I could do something hacky (like modify pHeads by a very small amount), but I was hoping there was some cleaner way to get the desired behavior.

도움이 되었습니까?

해결책

Here's the explanation of this behavior: Script to summarise data not updating

Read the comments to see suggestions on how to workaround it.

다른 팁

Pass a second param in that you ignore but which is different for each line.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top