Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice / Gauss Bell
#1
Hello Fellas,
 
Wow, I stumbled upon this tool and I'm massively impressed by it. On my first approach to the tool a year ago I started using it and trying it out.
 
What I read here on the forum and what you even made a FAQ for, is the topic related to the dice. As our playing groups got some worries here as well, I digged a little deeper into it.
 
Quote from your FAQ:
"Are the dice conspiring against me?
Short answer: No. Long answer: The dice use the standard Java random number generation routines. You can find them described in the Sun documentation. The same routine is used for every dice roll in the game. These routines have been tested, and they behave as closely as possible to real dice as is possible on a computer. To put it another way, every time the virtual die is rolled, it stands a one-in-six chance of generating each number, one through six, and each roll is independent of previous rolls. "
 
What I understood (correct me if I'm wrong), is that you used the standard java random number generator, right?
 
Which is fair in the sense, that if your roll a 6 sided dice 6000 times, it will generate a fair output of:
 
1: 1005x
2: 1028x
3: 1027x
4: 989x
5: 994x
6: 957x
 
 
results.
 
If you now take 2 dice, the standard random, as it is a computer produces a fair share like
 
02: 500x
03: 500x
04: 500x
05: 500x
06: 500x
07: 500x
08: 500x
09: 500x
10: 500x
11: 500x
12: 500x
 
Which is fair, but not like in a real world, which made a lot of people here complain.
 
The reason is, that in the real world, the more dice you take, the more you get a gauss bell curve of results.
 
like for example:
 
02: 100x
03: 200x
04: 350x
05: 450x
06: 600x
07: 750x
08: 750x
09: 600x
10: 450x
11: 300x
12: 100x
 
Here is a nice article about this problem in java code:
 
https://dzone.com/articles/java-programm...e-random-0
 
Quote:
 
-----------
Different Kinds of Randomness
 
Uniform Distribution
The Uniform Distribution is what you get by default from java.util.Random (and its sub-classes - including the Uncommons Maths RNGs). The discrete uniform distribution says that there are a certain number of possible outcomes and each is equally likely. The obvious example is rolling a dice. You can get a 1, 2, 3, 4, 5 or 6 and no single outcome is more likely than any of the others. If you record the results of 6 million dice rolls you would expect to get pretty close to a million of each number.
The uniform distribution is useful for some problems, such as shuffling a deck of cards, but it is not a good choice for many other scenarios that don’t involve a set of equally likely outcomes.
 
Normal (Gaussian) Distribution
The Normal Distribution (also known as the Gaussian Distribution) is the familiar bell curve. It is a good model for many real world phenomena. In a normal distribution, the average outcome is more likely than any other outcome. A slightly above or below average outcome is almost as likely, and extreme outcomes, while still possible, are very unlikely.
An example of this would be the distribution of IQ test scores. Most people would achieve somewhere close to an average score (maybe slightly above or below), but a few people would achieve very low scores and a similarly small number would achieve very high scores.
The nextGaussian() method of the java.util.Random class provides rudimentary support for obtaining normally-distributed values. Uncommons Maths’ GaussianGenerator class builds on this, making it easy to create distributions with different means and standard deviations. The standard deviation parameter controls how spread out the values are. A low standard deviation means most values will be very close to the mean (on either side). A high standard deviation increases the likelihood that a value will be a long way from the mean.
GaussianGenerator is a wrapper around a standard RNG (you can use any of the Uncommons Maths RNGs, or even one of the standard Java ones if you so choose). Once you have created a GaussianGenerator by specifying a mean, standard deviation and source RNG, you can call the nextValue() method ad infinitum:
Random rng = new MersenneTwisterRNG();
GaussianGenerator gen = new GaussianGenerator(100, 15, rng);
while (true)
{
    System.out.println(gen.nextValue());
}
If we were to generate thousands of simulated IQ test scores with this code, we would see that the vast majority of scores would be close to the average (100). Around 68% of the values would be within one standard deviation (15) of the mean (i.e. in the range 85 - 115), and approximately 95% would be within two standard deviations (between 70 and 130). These percentages are a well-known property of normal distributions.
The demo shows how the distribution of generated values compares to a theoretical normal distribution (the more values you generate, the closer the fit will be).
-----------
 
here is a Short demo about the results:
https://uncommons-maths.dev.java.net/demo/demo.jnlp
 
Do you think it would be possible to try this out? Like taking the code stated in the article and implement it in a test version? We would do some additional playtests then and see if the complaints vanish and I can finally force everybody in my group to use your great tool Wink
 
Thanks
 
and long live the Dragon  Smile
Reply
#2
Hello Babek. No need to worry. A 2d6 is rolled with the proper bell-shaped gaussian curve. The flat uniform distribution is applied only to a 1d6. To get 2d6 in the program, we basically run the random number generator twice so we virtually roll a 1d6 twice and then add the result. This ensures that we get the proper distribution for a 2d6 (or a 3d6, which we roll in a few cases like natural aptitude).
Reply
#3
Hi Taharqa,

jeah, that is what I thought and is addressed in the article, that just re-rolling the dice twice is flawed because the standard random is based on the CPU clock, which isn't changed much, if two instructions are run very close to each other.
So you need the gauss random options.

Would is be possible to release the class and method you use for the rolls? Maybe post it here? Just that little part of the code?

I would love to run the method 60.000x, put the results into an textfile and open it in excel to see the spread with an pivot table. This will help me then to calm my group of players, that their opinion is biased and the results shown there are flawless.

thanks and regards
Babek
Reply
#4
(09-21-2019, 02:49 AM)Babek Wrote: Hi Taharqa,

jeah, that is what I thought and is addressed in the article, that just re-rolling the dice twice is flawed because the standard random is based on the CPU clock, which isn't changed much, if two instructions are run very close to each other.
So you need the gauss random options.

Would is be possible to release the class and method you use for the rolls? Maybe post it here? Just that little part of the code?

I would love to run the method 60.000x, put the results into an textfile and open it in excel to see the spread with an pivot table. This will help me then to calm my group of players, that their opinion is biased and the results shown there are flawless.

thanks and regards
Babek

The article is discussing the default Sun RNG in java. MM gives you a choice of three different random number generators in the game options in RNG Type in Base Options. 1 (the default) does not use the default but rather the "crypto" version discussed as having better performance in that article. 0 will give you the Sun default RNG. 2 will give you a third option that draws from the 36 possibilities for a 2d6 directly with appropriate probabilities. So if your players really have issues you can have them use that one. 

Our project is open source so there is no need to release anything. Its all right there already. Information on the random number generator is spread out but the most relevant places are:

https://github.com/MegaMek/megamek/blob/master/megamek/src/megamek/common/MMRandom.java

https://github.com/MegaMek/megamek/blob/master/megamek/src/megamek/common/MMRoll.java

https://github.com/MegaMek/megamek/blob/master/megamek/src/megamek/common/Roll.java

However, there is really no need to run your experiment. You can turn on the game option to log all dice rolls. Then just run a big bot on bot game and look at the log file. You will need some skill at parsing out the dice rolls but the information is all there. 

For what its worth, I think even the default Sun RNG is fine. What you are talking about is serial autocorrelation which is unlikely to be a serious problem with any real RNG, even if its not optimal. Over the years, we have performed many tests on this issue, and detected no sign of serial autocorrelation. 

There is actually an active research field in cognitive science on human inability to understand randomness. When asked to generate a sequence of random numbers (from say 1 to 10) most people fail to do it. They typically induce negative serial autocorrelation by underestimating how common it is to get a sequence of the same or similar numbers. This is the same cognitive failure that generates suspicion of the RNG. Good luck with your players.
Reply
#5
Hi Taharqa,

thank you very much for the fast and detailed answers.

Best regards

Babek
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dice Rolls Lorian Sunrider 3 165 09-17-2017, 04:48 PM
Last Post: Arlith
  Gauss Rifle Exploding on ASFs Jayof9s 7 1,438 01-08-2012, 04:07 PM
Last Post: RedDevil
  Dice rolls Ravnos 2 1,040 06-06-2011, 10:25 PM
Last Post: Ravnos

Forum Jump:


Users browsing this thread: 1 Guest(s)