-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rollRange
under certain circumstances very likely to return the same result
#750
Comments
Tests now run 3 lots of 200,000,000 rolls of dice and check the distribution of the results in order to test the assertion made in #750
The problem might be fixed (I didn't test it) but I think you did miss something, The issue is not on the distribution of random values (e.g. calling |
@davesmith00000 @hobnob I'm not completely sure whether that fixes the issue. @JD557 is right that consecutive random numbers from the same generator should work, but it seems that every frame creates the RNG anew, and the first random number from a dice with 4 sides seems to be highly correlated to the next first random number. How should I best test the fix? Checkout the repo, publishLocal and test against that? Or is there a snapshot published? The first line tells you the number of times the first random number for a frame tick was equal to first number of the last frame tick. The second line tells how many times the second number was equal to the first in the same frame tick. The second number is at 25%, which seems correct given a 4-sided dice. The first number is 90%, though. |
Yup, that's how you would test this fix 🙂
I wonder if it's worth checking the seed you're passing here.. each time you call |
@JD557 I've just updated my unit tests to test the distribution of |
Of course - that doesn't address the over-weighting of the same number each frame, but I'm hoping the fix in #770 will do that 🤞 |
Tests now run 3 lots of 200,000,000 rolls of dice and check the distribution of the results in order to test the assertion made in #750
Hi All, We're going to merge the PR against this soon, because it will fix the problem. However, it moves the behaviour of the engine slightly away from the way it's supposed to work. @hobnob and I have discussed this at great length! That being the case, it's very likely that |
Tests now run 3 lots of 200,000,000 rolls of dice and check the distribution of the results in order to test the assertion made in #750
Tests now run 3 lots of 200,000,000 rolls of dice and check the distribution of the results in order to test the assertion made in #750
As per my previous comment: This PR deprecates As part of that work, random values will now be available in two ways:
|
The default java.util.Random handles calls to
nextInt(x)
wherex
is a power of two specially.In Indigo, this leads to the fact that when you do
dice.rollRange(1, 4)
at the start of everyFrameTick
, you are overwhelmingly likely to get the same number as before.Possible workaround: call
rollRange(1, 4)
(or with any other number) and discard the first return value. Successive calls seem to yield more random values.The text was updated successfully, but these errors were encountered: