Question

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.

Was it helpful?

Solution

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

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top