Problems with the random() function

I’m using the random() function to simulate the roll of two dice. A button invokes two independent function calls for dice 1 and dice 2 and tracks combined results of the two die and also the number of doubles rolled.

The number of doubles rolled is 33%, TWICE the expected 16.67%. This skews the number of times I get a combined result of 2 or 12 in particular. I’m wondering if I’m implementing this wrong? Or is there some problem with calling random() in quick succession? Please see the shared doc:

Thanks for any helps or ideas!

1 Like

Please share the the whole random() formulas .

it can’t show formulas on the shared doc.


Hi @Alan_Larsen1,
welcome to Coda community! :handshake:

I agree with you this is not the expected behaviour.
As @Steve_Yang was suggesting, having your Random() formula implementation (and its statistics) would be easier (either by posting it directly or giving sharing the document in edit mode, not the published link).

I see from the Random Reference that updateContinuously is default set to true; I guess (but it’s not fully clear) that this is changing at every document load the seed: have you already tried to set it to false?

1 Like

I think the issue is the share link rights. @Federico_Stefanato

it can’t edit column width(sometimes the text is not wrap, can’t see the whole column name ), can’t see formula , and can’t comment by select text and table) .

Thanks all for your quick comments on this and sorry about the link! I’ve added the code at the bottom of the page and a link to the doc with edit rights:

Thanks @Federico_Stefanato. I have tried both true and false on the random function. If false, the values only change with the first button press.

I think I found the issue…
@Alan_Larsen1, I added a section and it should now work.

Problem is that Random() is always the same in the same “context”.
In the same row, Random() will always return the same value in all the columns. It also happens in the formula.
This is why I did the multiple rows Random trick.
@Codans: is this what is intended?

Further, I added some intermediate results to better debug.
Now statistics seem to converge to their expected values.

Let me know if it helps.

Great catch and work-around @Federico_Stefanato! I knew something was going on, but couldn’t put my finger on it. I hope @Codans will fix this so calls to random() are always independent, but this works great for now - the actuals converge to the expected percentages as expected. Thank you!!

1 Like

Hi @Alan_Larsen1,

Welcome! And that’s an interesting find!
I’ve added this to our internal tracker so we can look into it more.

And thank you @Federico_Stefanato for tracking down where this was happening.

1 Like