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: https://coda.io/@alanlarsen/random-test
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?
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:
Hmmm…
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.
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!!
You are totally right, but I don’t have the faintest idea
My memory wipes out after every 11 seconds, this was 5 months ago…
Let me figure out what I did
Ah! Now I get it!
In the second page (https://coda.io/@alanlarsen/random-test/random-2-2), I created a table (Randoms) with two rows looked-up by the Test 2 table in two different columns (Random 1 and Random 2).
This allows to have two different random numbers because they belong to different rows and therefore applying each one per each dice.
I don’t know if this is relevant to your use case, but I suspect that the “Random() context” of the automation triggers the same random number every time.
While, pushing manually the button creates a new “Random() context” at each iteration.
Hi @Diacom_Hoofddorp
and welcome to Coda Community!
AFAIK, the problem should be sorted out, now.
If you put Random() as default value for a column, a different number should be picked (I just tested it).
Is it possible to share your doc or a sample of it?
Hi @Diacom_Hoofddorp
I understand what you say, now: in the same row, you have the sameRandom() call.
Doing some tests I discovered quite a weird thing…
If you put Random(false) (with literal) in one column and Random(False()) (with function) in the other, you do have two different seeds.
So: if you have two columns, the problem is sorted out.
However, you can’t have other variations (such as Random(True().Not()) is behaving like Random(False()).
@Codans, what about adding a standard Random(seed:long) function to overcome with this?