Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Dice Converter

Do you have some dice1, but not the right size?

Not a problem! This Dice Converter can convert between any size of dice with great efficiency, AND the output should be as uniform as the input!

Entropy: 0 bitsInput herePress on these
Number of faces on YOUR dice:
Roll and enter numbers here:
Target dice size:
Result #0N/A

How this works

You know how you can convert numbers between bases? Like between base 10 and base 2?

Well it turns out this also applies to any series of dice rolls!

For example, let’s say we want to convert the dice rolls from a d6 to those of a d10. Let’s say we got the numbers 2, 1, 5, and 6. Since dice usually start from 1 and numbers start from 0, we’ll have to remove 1 from each value. If we then put those together, we get 1045 in base 6 which in base 10 is 5 + 4*6 + 1*6^3 = 245.

This is the numerator of our fraction. Wait, a fraction!? Wasn’t it supposed to be about whole numbers? Well, because we want to extract digits from the left (since we inserted them from the right, and we want to make them flow like a nice conveyor belt), the most intuitive way is by imagining this is a fraction, while still only operating on whole numbers2.

So what’s the divisor then? What’s below the division line of that fraction? To make the value of the fractional number be in the range [0,1), the divisor needs to be one more than the max possible number of the random numerator, so in this case, 6^4 (since we have four d6 rolls), which is 1296.

Now, we have the fraction 245 / 1296. To extract a d10 out of this, we’ll divide the divisor by 10 (which will do the same as multiplying the numerator, while avoiding too-big numbers). BUT! We can’t do it like this, because the divisor is not divisible by 10 yet. It has an extra range of 6 possible values we can’t care about if we want to avoid biasing the output3. More formally, that extra range is 1296 % 10 = 6, where % is the remainder operator.

Let’s remove that. So the fraction is now 239 / 1290. See what I did here? I removed the “extra” range (6, in this case) from both numbers of the fraction. The divisor is now cleanly divisible by the number of faces of a d10. The only case where this does not work is when the numerator of the fraction is smaller than the “extra” range. In that case, the “extra” range should become the new divisor, and we could not extract a digit before re-rolling, because the range would be too small.

The first digit we’ll extract is the integer part of 239 / 129 = 1.853, which is 1. To get back a suitable numerator, we have to remove that 1 from the fraction, so (239 - 129) / 129 = 110 / 129. Remember when I said dice usually start from 1 and digits from 0? Well, to get the first d10 result, we’ll have to add back that 1. So 1 + 1 = 24.

The first d10 roll is 2.

Then repeat the above process with 110 / 129, to get 101 / 120, then 101 / 12 = 8.417 to get 8 as the whole number part, then remove that 8 from the fraction and get (101 - 96) / 12 = 5 / 12. Adding back the missing 1, the second resulting roll is 8 + 1 = 9.

The divisor of 5 / 12 is still bigger than 10 (we want d10 rolls, remember?), so we can get a third roll from that. If you’ve followed all the way through here, you should be able to figure out why the third calculated roll is 3 + 1 = 4.

There you go. That’s exactly how this converter can get 3 fair d10 results from 4 fair d6 rolls, which in this example achieves 96% of the theoretical maximum conversion rate.

To see whether that explanation is still valid or not, simply use the converter above with by setting the Number of faces on YOUR dice to 6 and the Target dice size to 10, then select the field next to Roll and enter your numbers and type 2 Enter 1 Enter 5 Enter 6 Enter, and then click on Calculate a few times to see appear 2, 9, then 4.

Conversion Efficiency

In the process of keeping a uniform probability distribution for the output, this tool discards some parts of the input (as described above).

The maximal theoretical efficiency for converting between dice sizes is log(input_size) / log(output_size).

For example, the maximal theoretical efficiency of converting a d12 to a d4 is log(12)/log(4) = 1.79, while the observed average efficiency of this tool is 1.54 for non-batched d12 to d4 conversions, making that a ratio of 1.54/1.79, so 86%, as shown in the table below. For reference, the naive way to convert a d12 to a d4 (mapping all slices of 3 consecutive values to a single face on a d4) would have an efficiency ratio of 1.00/1.79, so 56%.

The following table lists the ratio between the observed efficiency and the maximal theoretical efficiency when calculating rolls as soon as it’s possible (i.e. when not batching).

d4d6d8d10d12d20d100
d4100%71%100%77%77%83%88%
d676%100%84%77%87%79%90%
d8100%76%100%82%87%87%91%
d1078%75%83%100%88%94%100%
d1286%92%82%83%100%89%90%
d2083%85%85%94%81%100%95%
d10087%90%87%100%91%94%100%

When batching (inputting a bunch of rolls before calculating outputs), however, the efficiency is much, much better in all cases (usually more than 97% of max theoretical efficiency). See for yourself by opening the section below and playing with the parameters used to generate the above table.

Generate variations of the efficiency table

The following recreates a table similar to the above by generating 131072 (217) random numbers as input dice to the dice converter, and then measuring how many rolls can be generated out of that for each pairs of sizes in the dice size list. You can compare the conversion between any dice sizes you want.

If the delay annoys you when generating the table, either try with fewer dice sizes, or reduce the number of input rolls. This is using the actual code of the dice converter, and the default configuration makes it process more than 6 million rolls to generate the table.

What the data of the table represents:
Dice sizes list:
How many input rolls (max 220):

A markdown version of the same table should also be generated below.

Why

Some dice sizes are not satisfying to roll.

Converting between dice sizes is silly when you could instead use a Random Number Generator. That’s what people say when they see this tool. Anyway, it is a mathematically interesting problem to solve. It looks like a very easy problem, but that’s only true for trivial cases. A great motivator for trying to make it work in all cases, including when the dice sizes are coprime, is having your own almost-working version posted online. It gives a sense of responsibility to fix it, even if no one really cares5.

It’s weird how this seems to be the first ever any-to-any online dice converter. Searching for something similar only seems to lead to online random number generators. Is this such an unnecessary tool? Probably. At least now it exists!


  1. Make sure the smallest value on your dice is 1, since the program here currently assumes this.

  2. Actually, while implementing it, I didn’t even think of it as a fraction. At the time, I thought of them as a pair of numbers where one is a random number in a certain range, and the other is the upper bound of that range. So the most intuitive way to extract digits from the most significant side of the number (when I was thinking about the direction of the extraction) was to divide the upper bound by the output dice size, and then dividing the stored random number by that. I didn’t even think about multiplication in that case! But when trying to explain how it works, a fraction better conveys the message. And the division helps to avoid the integer overflows that could happen when multiplying.

  3. We cannot keep out-of-desired-range numbers “for later” when trying to avoid the bias, because that would introduce another bias. What is done here (throwing away what doesn’t fit) is called rejection sampling, and it’s what makes the output have the same probability distribution as the input.

  4. Hmm. 1 + 1 = 2. That equation seems familiar…

  5. Note that such dedication is not necessarily shared among all contributors of Nazarax, and that “I” may refer to different people when seen on different pages.