Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A little bit of math here.</p> <p>A regular die will give each number 1-6 with equal probability, namely <code>1/6</code>. This is referred to as <a href="http://en.wikipedia.org/wiki/Uniform_distribution" rel="noreferrer">uniform distribution</a> (the discrete version of it, as opposed to the continuous version). Meaning that if <code>X</code> is a random variable describing the result of a single role then <code>X~U[1,6]</code> - meaning <code>X</code> is distributed equally against all possible results of the die roll, 1 through 6.</p> <p>This is equal to choosing a number in <code>[0,1)</code> while dividing it into 6 sections: <code>[0,1/6)</code>, <code>[1/6,2/6)</code>, <code>[2/6,3/6)</code>, <code>[3/6,4/6)</code>, <code>[4/6,5/6)</code>, <code>[5/6,1)</code>.</p> <p>You are requesting a different distribution, which is biased. The easiest way to achieve this is to divide the section <code>[0,1)</code> to 6 parts depending on the bias you want. So in your case you would want to divide it into the following: <code>[0,0.2)</code>, <code>[0.2,0.4)</code>, <code>[0.4,0.55)</code>, <code>0.55,0.7)</code>, <code>[0.7,0.84)</code>, <code>[0.84,1)</code>.</p> <p>If you take a look at the <a href="http://en.wikipedia.org/wiki/Uniform_distribution" rel="noreferrer">wikipedia entry</a>, you will see that in this case, the cumulative probability function will not be composed of 6 equal-length parts but rather of 6 parts which differ in length according to the <em>bias</em> you gave them. Same goes for the mass distribution.</p> <p>Back to the question, depending on the language you are using, just translate this back to your die roll. In Python, here is a very sketchy, albeit working, example:</p> <pre><code>import random sampleMassDist = (0.2, 0.1, 0.15, 0.15, 0.25, 0.15) # assume sum of bias is 1 def roll(massDist): randRoll = random.random() # in [0,1) sum = 0 result = 1 for mass in massDist: sum += mass if randRoll &lt; sum: return result result+=1 print roll(sampleMassDist) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload