27
\$\begingroup\$

Imagine you are trapped in a post-apocalyptic world and only have a single d20 at your disposal, nothing else whatsoever. What is the ideal way of emulating all other common dice types (d4, d6, d8, d10, d12, d%) using just this d20 and arbitrarily complicated math?

I realize there's an easy way to make due with a single d6 (using the same d6 also for a coin-like mechanic), but I was wondering if this also works with a d20, and what the criteria are for this to work with a dN, if there is any research on the matter.

Let me preface this by defining a few pointers:

"ideal" = as few d20 rolls as possible.

"emulating" means mapping output from one or more d20 rolls to whichever die you want to emulate, while maintaining statistical accuracy - each possible output for the desired die must be equally likely.

"to map" a number X to an interval [1; B] means to apply an operation of the following form:

$$ dB = X - B \times \textbf{int}\left[\frac{X - 1}{B}\right] $$

where the int[] operation demands rounding down (truncation, since the argument will never be negative for the given problem).

Here's what I have so far, in order of complexity:

Single roll \$X\$: d10 = \$[X]\$ if \$[X \leq 10]\$, else: \$[X - 10]\$

Single roll \$X\$: d% is equivalent to d10.

Single roll \$X\$: \$\textbf{d4} = X - 4 \times \textbf{int}\left[\displaystyle{\frac{X - 1}{ 4}}\right]\$

Two rolls \$X\$, \$Y\$: d8 = \$[X]\$ if \$[X \leq 8]\$, or \$[X - 8]\$ if \$[9 \leq X \leq 16]\$. Alternatively, for \$[X > 16]\$, d8 = \$[Y]\$ if \$[Y \leq 8]\$, or \$[Y - 8]\$ if \$[9 \leq Y \leq 16]\$. Alternatively, if both \$[X > 16]\$ and \$[Y > 16]\$, d8 = \$[X - 16]\$ if \$[X+Y]\$ = even, else: \$[X - 12]\$.

Three+ rolls \$X\$, \$Y\$, \$Z\$: \$\textbf{d6} = X - 6 \times \textbf{int}\left[\displaystyle{\frac{X - 1}{6}}\right]\$ if \$[X \leq 18]\$. If not, check the same for \$Y\$. If not, check the same for \$Z\$. If \$\left\{X, Y, Z\right\}\$ in \$\left\{19, 20\right\}\$ (which has a 1/1000 chance of happening), map the combination to \$[1;6]\$. However, I don't think it is possible to reliable get this mapping even when adding more and more dice rolls. Of course, it will get vastly unlikely rather quickly, but there does not seem to be a reliable way of using binary values to map to 6 reliably, seeing as it is a product of two primes. What is the lowest number of dice rolls required to achieve a 100% successful outcome, if it is possible at all?

The same issue applies to the d12, which can be constructed trivially from a d6 by rolling a d20 like a coin toss, then either using the initial d6 value or d6+6. This might not, however, be the ideal solution for this.

I would greatly appreciate any insight into the matter, as this has kept my mind busy for quite some time now. I'm pretty sure it cannot be reliably done for the d6 and d12, but I would appreciate any kind of closure or proof you peoples might be able to provide!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Are you allowed to write on your d20? \$\endgroup\$ Sep 30, 2020 at 13:31
  • \$\begingroup\$ Would that change anything? I'd be happy to allow it if it helped tackle the problem in any way. I just realized that you might be able to introduce 3 directions for each roll that way - if that was your line of thought, the orientation of the number with respect to a fixed point might suffice? It wasn't what I originally had in mind. But I like the idea. I guess in the scenario I proposed here, more of a mathematical construct, you wouldn't be able to write on it. \$\endgroup\$
    – Chivalry
    Sep 30, 2020 at 14:07
  • \$\begingroup\$ Related on using d6's for emulation: Is it possible to emulate common polyhedral dice rolls using just a d6, and if so, how? \$\endgroup\$
    – Someone_Evil
    Sep 30, 2020 at 14:47
  • 7
    \$\begingroup\$ Why are you trying to play D&D alone when you're naked and stuck in a post-apocalyptic world with nothing but a single D20? Shouldn't you be trying to find food and shelter? \$\endgroup\$
    – J...
    Oct 1, 2020 at 12:46
  • \$\begingroup\$ See also- math.stackexchange.com/q/1273214 \$\endgroup\$
    – Sam Weaver
    Oct 1, 2020 at 21:28

12 Answers 12

36
\$\begingroup\$

Emulating a d6 using a fixed number of d20 rolls is impossible.

Of course, as the other answer points out, it is possible to do so if we take into account more than just the rolled result, such as its orientation, but let's ignore that for a moment.

You rightly say that we can emulate a d6 with a d20 by mapping 1-18 to the d6 and rerolling on 19 or 20. This works, but this could in theory go on forever if we keep rolling above 18.

So, why is it impossible? As you said it has something to do with factorization. A d6 is impossible to create with a d20 not because it is the product of two primes, but rather because it has a prime factor which is not present in the prime factorization of 20. Firstly, note that the reason that we can't emulate a d6 with a single d20 is because 20 is not divisible by 6. Now, the prime factorization of 6 is \$2 \times 3\$, and that of 20 is \$2^2 \times 5\$. If we roll \$n\$ d20s, this gives a total of \$20^n\$ possibilities. Because multiplication is the same as adding the prime factors, \$20^n\$ will have \$n\$ times the factors:

$$ 20^n = 2^{2n} \times 5^n $$

That is, regardless of the amount of times we roll a d20, the total amount of possible results will never have a prime factor other than 2 or 5, and will therefore never be divisible by 3. Because every outcome is equally likely, there is therefore no way of distributing these outcomes over the faces of a d6 such that all 6 possibilities are equally likely.

More generally, a dX can emulate a dY if and only if X has all prime factors that Y has. Therefore, a d20 cannot emulate a d3, d6, d12 or d35, but it can emulate a d8, d10 or d4294967296.

Example of emulating a d8 with a d20

If we wish to emulate a d8 with a d20, we first note that 20 is not divisible by 8. This is because 8 has three 2s in its prime factorization, and 20 has only two. However, \$20^2\$ has factorization \$2^4 \times 5^2\$, which encapsulates the prime factorization of 8, and therefore we need only two d20 rolls.

Now, all we needed from one of those rolls was a single factor 2, so we can use one of them as a coin flip. Therefore, we can roll the first d20 and if it lands on the top half (11-20), we take something from the top half of the d8 (5-8), and similarly for the bottom half (1-10) -> (1-4). Then we only have to divide the other d20 in four categories: (1-5) -> (1 or 5); (6-10) -> (2 or 6) and so forth.

Note that this is only an example, and there are plenty of ways to emulate a d8 with two d20s. All you have to do is ensure that out of the 400 possibilities with two sequential d20s, 50 of those possibilities are assigned to each of the 8 target numbers, which is equivalent to cutting the space equally in two a total of three times.

\$\endgroup\$
3
  • \$\begingroup\$ Re "More generally, a dX can emulate a dY if and only if X has all prime factors that Y has.", So the smallest singular die that can emulate a standard set (d4,d6,d8,d10,d12,d20,d100*) is a d(2*3*5) = d30. All hail the new d30! It would be simpler with a d(2*2*2*3*5*5) = d600, though. (600 is the smallest number evenly divisble by the 4,6,8,10,12,20,100*.) [* A standard 7-dice set has two d10 dice to allow rolling a d100.] \$\endgroup\$
    – ikegami
    Oct 2, 2020 at 7:33
  • \$\begingroup\$ There's a more elegant way of phrasing this: you can simulate a roll of a dX with a bounded number of rolls of a dY if 1/X written in base Y terminates. (And as a bonus, the number of digits after the decimal point is the upper bound on the number of rolls needed.) \$\endgroup\$ Oct 3, 2020 at 0:18
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$
    – Kevin
    Oct 3, 2020 at 5:47
25
\$\begingroup\$

An Icosahedron has 12 vertices.

Since an icosahedron has 12 vertices, all we need is a method for identifying the vertex which corresponds to a particular result.

Orientation

Each face of a d20 is a triangle, so we can easily determine which vertex is the result based on its orientation relative to us. Simply take the vertex that is the furthest away or "on top" as the resulting vertex. If two vertices are on top, take the bottom. Maybe this isn't perfect, it will require a bit of a judgment call, but it should be a pretty clear result all of the time. To mitigate this, we can fashion a dice tray with ruled lines to help us make that judgment.

Determining the result

Now we just have to determine the result. This will be a little tedious, but we can get it done by writing down and consulting the following table. I constructed this table based on one of my d20s, but you can construct your own if it is different, it will still work.

Once you have chosen your vertex, map the vertex's corresponding faces to the left most column of the table to get your d12 result. A d6 result is had by dividing the d12 result by 2 and rounding up. $$ \begin{array}{|c||c|}\hline \text{Result} &\text{Vertex Faces}\\\hline 1&1,5,7,13,15\\\hline 2&1,3,7,17,19\\\hline 3&1,9,11,13,19\\\hline 4&2,8,10,12,20\\\hline 5&2,4,14,18,20\\\hline 6&2,5,12,15,18\\\hline 7&3,6,9,16,19\\\hline 8&3,8,10,16,17\\\hline 9&4,6,9,11,14\\\hline 10&4,5,11,13,18\\\hline 11&6,8,14,16,20\\\hline 12&7,10,12,15,18\\\hline \end{array}$$

Example 1

So I rolled a d20 on one of my character sheets at DnDBeyond. Here is the result:

enter image description here

It is easy to see which vertex is "on top", so that vertex corresponds to {6,8,14,16,20}, which gives us a result of 11 on the table.

Example 2

Here is a result where there is no clear "on top" vertex:

enter image description here

Here we choose the bottom vertex, which has faces {4,5,11,13,18} which gives a result of 10 on our table.

The d8.

For the d8, first, convert your roll to a d4 by 1+(d20 modulo 4). Then, if the vertex at the top of the result number is away from you, add 4, else keep the d4 result.

User Rayllum came up with this solution and first communicated it to me in chat. He has since included it in their answer here, and have presented other solutions to the problem here. Go give his answers some love.

\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ Oct 2, 2020 at 13:01
17
\$\begingroup\$

To directly implement a d6 or a d12, you can increase your d20 to a d60, by using the fact that

Every face of a standard d20 has 3 distinctive vertices.

Looking at an example face, it is seen that the number defines the 'up' direction, as well as 'left' and 'right':

Two triangles (left and right). The left triangle displays a 5 in the middle and the corners are denoted "up", "left" and "right". The right triangle is a rotated version of the left triangle

Therefore, the three vertices of a face can be distinctively described as "upper vertex", "left vertex" and "right vertex".

After the die is rolled, you look not only at the rolled number, but also which of the three vertices is furthest away from you.

  • If the "upper vertex" is furthest away from you, use the rolled number as-is.
  • If the "right vertex" is furthest away from you, add 20 to the rolled number.
  • If the "left vertex" is furthest away from you, add 40 to the rolled number.

Then, de facto you have a d60. This allows for a direct implementation of a d12 (by dividing the numbers 1-60 into 12 partitions of the same size).

Alternatively, using the formula of the question:

Single roll \$X\$: \$\textbf{d12} = X - 12 \times \textbf{int}\left[\displaystyle{\frac{X - 1}{ 12}}\right]\$

Similarly for other factors of 60, e.g. 6, 15, 30.


Thanks to Thomas Markov and Someone_Evil for their contributions to this answer.

\$\endgroup\$
13
\$\begingroup\$

By putting the d20 in your pocket

You don't need a die to emulate a die. Have the GM secretly choose a whole number. Have the player rolling declare some other whole number. Add the two together and then take the modulo of that sum by the size of the die to be emulated.

I've done this for years on account of being poor and not always having internet until recently. While it can take a little bit for players new to the system to learn how to pick numbers well (c.f. How to Win at Rock Paper Scissors), over time play approximates a fair die quite well, and it only ever takes one "roll".

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Wouldn't there be an issue where since no rolls are performed then the players might think the GM is being biased? Additionally the GM might think the same and not want to pick arbitrary numbers on the base of: oh hey I don't want to accidentally TPK so I should only do high numbers. \$\endgroup\$ Oct 1, 2020 at 2:27
  • \$\begingroup\$ @TheGrandJ The GM picks first for that reason. If you can't trust your GM for some reason, you have them write it down, or tell another player, but in my experience as long as the GM actually picks a number when it is their turn, it works fine-- most people who can't be trusted also suck at GMing. Also high numbers don't make good rolls. \$\endgroup\$ Oct 1, 2020 at 2:54
  • 2
    \$\begingroup\$ high numbers don't increase or decrease any chances. gm: chooses 95. player: chooses 15. result is 110. emulating a d20 is 110 % 20 = 10, so the roll was a ten \$\endgroup\$
    – clockw0rk
    Oct 1, 2020 at 15:31
  • 4
    \$\begingroup\$ I upvoted for uniqueness, but I have to agree with @TheGrandJ. Even if you aren't trying to be biased, if you know your players and know what numbers they are likely to pick, you will still have a subconscious inclination to pick numbers the complement or contrast those numbers. And if you are writing them down, rather than waste paper and pen(cil)s spent the buck to buy a d20. \$\endgroup\$ Oct 2, 2020 at 0:15
  • 2
    \$\begingroup\$ Humans are terrible random-number generators, although I expect combining two bad random numbers via sum and modulo helps a lot. (e.g. humans will rarely pick the same number twice in a row because that seems "not random"). Fortunately for D&D, the way we use them is often pass/fail thresholds or just damage totals, so many measures of statistical quality are probably less important than for a physics simulation / computational experiment. \$\endgroup\$ Oct 2, 2020 at 3:32
12
\$\begingroup\$

In theory, you can simulate any die if you

Think of your d20 as a compass.

The idea is to split \$360^\circ\$ into N even parts and let the "compass" select a part. (Similarly to a Twister spinner).

To simulate a dN, you roll the die and ignore the value of the number rolled. Instead you look where the "upper vertex"1 points to. Then, take the angle \$ \alpha \$ between the direction 'towards you' and your "upper corner" direction. E.g. if the "upper corner" points away from you, then \$ \alpha = 180^\circ\$; if the "upper corner" points to your right, then \$ \alpha = 270^\circ\$.

For exactly one integer \$ X \$ you have \$(X-1) \cdot \frac{360^ \circ} N \leq \alpha < X \cdot \frac{360^\circ} N\$. That \$ X \$ is your "rolled" number.

E.g, if \$ N=4\$, then any roll with "upper vertex" direction \$\alpha\$, where \$1 \cdot 90^ \circ \leq \alpha < 2 \cdot 90^\circ \$, results in the "rolled" number \$ 2 \$.


While this approach is very theoretical and in practice hardly applicable for large \$ N\$, it actually can be used in practice to

Roll the d8 in one throw

Roll the d20 and use the rolled number as it would be done for a d4. Then, if the upper corner faces you (50% chance), add 4.

Generalized: To simulate a dN with a d20, calculate the greatest common divisor: \$ g = gcd(N, 20)\$. Then (if \$g < N\$), apply the compass-method to get a d\$ \frac N g \$ dice. Use the rolled number of the d20 to simulate a d\$ g\$.

Combining the d\$ \frac N g \$ and the d\$ g\$ yields a d\$ N\$

1See my other answer for the definition of "upper vertex".

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Alright, very good - now I get what you meant. Excellent point, and this is actually swifter than what I came up withfor the d8! Though I think in the context of a d12 roll this still looses to vertices in terms of simplicity, simply because measuring that angle would be rather difficult in practice. For a d12, you could look at the direction of the number to [1;6] and then use odd/even to either use the straight number or add 6 - I suppose that would make it easier. \$\endgroup\$
    – Chivalry
    Sep 30, 2020 at 20:17
  • \$\begingroup\$ Yep, for large N this is a purely theoretical approach. For the d12 you can even go down to [1;3] for the direction and use the d20-result to decide whether to add 0, 3, 6 or 9. \$\endgroup\$
    – Rayllum
    Sep 30, 2020 at 20:21
  • \$\begingroup\$ The previous two comments refer to an older version of this answer. To improve readability, the feedback & explanations of these comments are now included. \$\endgroup\$
    – Rayllum
    Sep 30, 2020 at 22:43
  • \$\begingroup\$ Sometimes the die angle is going to be too close to the cutoff to judge, so it's effectively "cocked" and you have to reroll. As I showed in my answer, the expected number of rolls for the simple d20 / 2 round up, discarding 17..20, is 1.25 d20 rolls per d8. That's only slightly more than I'd expect from this method, but still interesting idea. \$\endgroup\$ Oct 2, 2020 at 3:35
  • 2
    \$\begingroup\$ @PeterCordes In practice you can still say: If it's too close to judge, take the higher number (A variant of Example 2 of Thomas Markov's answer). In the end, similarly to any sports "in- or out-of-field" case, you have to make a decision. Reading your comment actually gave me an idea on how to bring 1.25 down to 1.2 - I'll write it below your answer for readability. \$\endgroup\$
    – Rayllum
    Oct 2, 2020 at 10:35
9
\$\begingroup\$

Summary:

  • Rolling and discarding averages fewer than 2 d20 per any other die, even d12. This is good for time and the stated criterion of number of rolls.
  • Divide and round up is easier than actually working through your formula, and maybe easier than doing the modulo-like operation that's equivalent to your formula, except for d10 where you just take the trailing digit. This is more ideal for time, same number of rolls.
  • idea from @superb rain in comments, not yet incorporated into this answer except for d4: often 1 player needs to roll multiple d6s or d8s (or d12s) in the same turn. A single d20 can give us a d8 and a d2 result without correlation, for example, letting us chain rolls by giving us a d8 output and some leftover entropy. With clever math, we can even reduce the number of d20 rolls per d8 below 1 when rolling multiple d8s. If someone wants to write this up as a new answer, I'll link to it here.

Discarding random samples is the standard way of avoiding bias when creating a uniform distribution from an RNG that generates a larger range than what you want, and the range isn't an exact multiple1. It's simple, easy to remember and understand, and probably quick to do in practice.

But how many rolls will we need on average with the simple re-roll method, e.g. discarding 19 and 20 when trying to roll a d6? Expected number of rerolls for simple sampling, discarding and rerolling 2 out of 20 numbers for a d6 (20 mod 6=2), 4 out of 20 for a d8 (20%8=4), 8 out of 20 for a d12 (20%12=8).

  • d4: 1.0
  • d6: sum((2/20)^n, n=0..inf) = 1.11111...
  • d8: sum((4/20)^n, n=0..inf) = 1.25
  • d10: 1.0
  • d12: sum((8/20)^n, n=0..inf) = 1.6666...

These are all less than 2, even for d12. Any method that always rolls 2 dice is on average more rolls than rerolling. In the worst case for rerolls (d12), you don't have to do any math (just take the 1..12 result from the d20) so the total time spent to get a number is still not bad.

The chance of rolling 19 or 20 is 1 in 10. The chance of doing it again is 1/100, etc. The series 1/10 + 1/100 + 1/1000 + ... converges to 0.1111... extra d20 rolls per roll d6 roll, if I have the logic correct.

@Rayllum suggests in comments that instead of just discarding, switch strategy. e.g. for d8, on 17..20 use that as a d4, then the next roll determines whether to add 4 or not. i.e. the 2-roll d4 + 4*d2 strategy suggested in another answer. This reduces the average number of rolls for a d8 to 1.2, and sets a hard upper bound of 2. Similar tricks are possible for other dice.


But at least you don't have to do any math when you reroll, only on the one that's eventually in the right range. Rerolls are "cheaper" than other multiple-roll strategies because they can be done quickly with little mental effort, and uses the die "as intended" with no need to judge angles, just read the face. You do still need to do math at the end on the one die result, but that can be simpler than a formula that involves 2 inputs and larger intermediate values.

A rare long string of high d20 rolls might be amusing itself, or might just be frustrating ("where were these rolls for my attacks / saving throws / checks?")

Possibly some players who haven't overcome the gambler's fallacy would be frustrated that they're "wasting" all their high rolls by having to discard them. Discarding low rolls and shifting the mapping would make the math slightly less simple (1 extra subtraction step at the start), but might make some players happier (than discarding high rolls).


Frame challenge: time, not just number of rolls, is probably the real concern

Clever outside-the-box answers have suggested using other properties of dice / angles, but some of them might make each roll take longer (e.g. judging the angle and/or consulting a lookup table of vertices).

Minimizing the average time to result is probably a better real-world goal than minimizing number of rolls. This part is a frame-challenge based on your post-apocalypse premise. The actual math question of finding minimum-rolls is also interesting.

With time in mind, let me suggest a simpler formula for mapping d20 rolls to smaller ranges. Your formula based on floor $$X - B \times \left \lfloor{\frac{X-1}{B}}\right \rfloor$$
is equivalent to 1 + (x-1)%B, a remainder from 1..B instead of 0..B-1. e.g. for B=4, it goes 1,2,3,4, 1,2,3,4, etc. I think it would be easier to directly use quotient rounded up ("ceiling").

$$\left \lceil{\frac{X}{5, 3, \tt or\ 2}}\right \rceil$$

This has the benefit for humans that higher numbers on the d20 are higher numbers on the d4 / d6 / d8 / d10 / d12.

e.g. for a d4, it's fairly intuitive to see where your number falls in the four ranges 1-5, 6-10, 11-15, 16-20. This works out nicely because 5 is a factor of 10, the number base we're used to using. Or just think of it as d20/5 round up.

Unfortunately we can't do it both ways on the same d20 to get 2d4 from one roll. (Unless you're rolling a lot of d4s and don't mind the correlation). 1 on the ceil(x/5) makes 1 on the 1+(x-1)%4 twice as likely as other results. Same with other numbers. (A different mapping could give opposite correlation, making rolls more likely to tend towards the average instead of away). You could do d20/4 and d20%4 for 2 independent d4 results, or just 1 if the roll was 17..20. With 2 players looking at the same d20 roll, one can total the the 1 + (x-1)%4 in their head, and the other can total the ceil(x/4), saving time for a player to roll magic missile damage or a healing potion.

For a d6, d20/3 round up is probably not as intuitive for most people, but I expect it's something you can quickly get good at. (Unless 5e mechanics of rounding down for damage resistance leads to frequent mistakes...) You could write down a table which is easy to visually search because d20 input and d6 output are both in ascending order.

For a d8, divide by 2 round up (and discard rolls 17..20). Or use your formula, which amounts to subtracting 8 or not for the high half of the acceptable range. That's also fairly simple and avoids "divide by 2 round up" which is very close to, but different from, standard 5e divide by 2 round down damage resistance. It probably comes down to experience which is mentally easier overall. Or discard 1 and 18..20, then divide by 2 round down.

For a d10, your way amounts to ignoring the leading digit (treating 0 as 10) which should be very quick and intuitive (and less risk of error) than dividing by 2 round up. Also avoids conflicting number-memory for damage resistance = divide by 2 round down.

For a d12, it's trivial math ("divide by 1"). The only cost is in a larger number of expected/average rerolls.


Footnote 1: In computer programming, rand() % 12 has only a tiny bias and can be "good enough" when rand() can produce numbers up to 2^32-1, but a huge bias when it produces numbers from 0..19. That would produce a random number from 0..11, but not uniformly distributed. The numbers 0..7 would come up twice as often as 8..11

Similarly, rand() / (RAND_MAX/12) has bad bias for small numbers like 12 because the range isn't evenly divisible into 12 equal-sized chunks.

I mention this only to point out that this problem is basically similar to one that's been studied extensively for computing. Doing it by hand, and with small ranges, makes the tradeoffs different.

\$\endgroup\$
0
3
\$\begingroup\$

A d20 roll has more information than a d6 roll (or any other of the smaller dice). Thus it should be possible to average less than one d20 roll for a d6 roll. To be more precise, log(6)/log(20)=0.5981 rolls of the d20 should suffice. How can it be less than one? Imagine emulating a d2 with a d4. Each d4 roll is worth two d2 rolls (take the d4 result divided by 2 as one d2 result, and take it modulo 2 for another), so d2 averages 0.5 rolls of d4.

For all requested dice with N sides:

 N   ideal d20 rolls
--------------------
 4   0.46276
 6   0.59810
 8   0.69413
10   0.76862
12   0.82948

Emulating d2 with d4 is easy. How do we get such efficiency for emulating let's say d6 with d20? Let's roll the d20 twice right away. That gives us 400 possible different outcomes. That's 6 buckets of 66 outcomes each, and 4 leftover outcomes. Now:

  • If the actual outcome falls into one of those 6 "good" buckets, we use the bucket number as a d6 result. But don't throw away where in the bucket we are! We can keep using this range of size 66 for further rolls.
  • If the actual outcome is one of the 4 leftovers, we don't get a d6 result yet. But don't throw away which leftover we have! We can keep this range of size 4 for further rolls. Now grow it back up to over 1000 and try again until we do get a d6 result.

More technically:

  • We'll keep two things: limit, and a number value in the range [0, limit). And every number in that range has equal probability to be value. Start with limit=1 and value=0.
  • Whenever we want a new result for dN, first increase the size of the range to let's say limit≥1000. Do this by multiplying both limit and value with 20 and adding a new d20 roll result to value. Then apply the above case distinction, i.e., very likely get a dN result and retain a fairly large range, or very unlikely don't get a dN result and retain a fairly small range.

Note that for example for d4, in the very likely "good" case we not only get a d4 result, but also only shrink the range by about factor 4. While d20 rolls to grow the range grow it by factor 20. So two d4 results are shrinking the range more slowly than a one d20 roll grows it back up. This is how we average more than two d4 results per d20 roll. Or equivalently, how we average less than 0.5 d20 rolls per d4 result.

Results from doing that in Python, with one million rolls for each N:

       d20 rolls
 N  average  ideal     average / ideal
----------------------------------------
 4  0.46385  0.46276  1.0023523685865143
 6  0.59994  0.59810  1.0030630049027711
 8  0.69634  0.69413  1.0031713739604955
10  0.77008  0.76862  1.0019010821509053
12  0.83293  0.82948  1.0041577531922499

Note that the actually occurred averages are very close to the ideal ones. And: Remember that the "good case" not only gives us a dN result but also retains a much larger range. And we can make the good case more likely simply by keeping the range larger. I used what I said above, making limit≥1000. The larger you make it, the closer you get to ideal.

Full Python code (you can run it at repl.it, though there I reduced the rolls to 100,000):

from random import randrange
from math import log

def d20():
    """Return random integer from 0 to 19."""
    global d20_rolls
    d20_rolls += 1
    return randrange(20)

value, limit = 0, 1
def dn(n):
    """Return random integer from 0 to n-1."""
    global value, limit
    while True:
        while limit < 1000:
            value = value * 20 + d20()
            limit *= 20
        multiple = limit - limit % n
        if value < multiple:
            result = value % n
            value //= n
            limit //= n
            return result
        value -= multiple
        limit -= multiple

rolls = 10**6

for n in 4, 6, 8, 10, 12:
    d20_rolls = 0
    for _ in range(rolls):
        dn(n)
    average = d20_rolls / rolls
    ideal = log(n) / log(20)
    print('%2d' % n, '%.5f' % average, '%.5f' %  ideal, average / ideal, sep='  ')
\$\endgroup\$
3
  • \$\begingroup\$ This is getting pretty far from what you'd want to actually do by hand / in your head. Interesting to work out the theoretical minimum for breaking up entropy into dX rolls, and a math method, but doing it by hand would be slower and more error-prone than other ways. e.g. for a d4, you might want to use results of 1..16 to get 2d4, or 17..20 to get 1d4. (x/5 and x%4 are somewhat correlated so we can't always get 2d4 from a single d20 with a simple fast mental calculation.) (I mentioned this 2d4 idea in my answer about actual practical methods you might truly use post-apocalypse.) \$\endgroup\$ Oct 3, 2020 at 4:35
  • 1
    \$\begingroup\$ @PeterCordes True, but they allowed "arbitrarily complicated math". Plus, post-apocalypse is hopefully far in the future, and until then our brain power is surely enough for this :-) \$\endgroup\$ Oct 3, 2020 at 4:38
  • \$\begingroup\$ Also interesting is the actual payoff for your method, i.e. if n d20 are rolled, how many d8 can de facto be used. If I calculated correctly, it's hard to get significantly better than 7d20 yielding on the average 9.78d8's, so 1.40 per roll. The next significantly better value is 16d20s with 22.80d8's (1.42 per roll) but sorting and dividing 16d20s seems not so practical. \$\endgroup\$
    – Rayllum
    Oct 3, 2020 at 10:07
2
\$\begingroup\$

To be able to emulate all of the required numbers, you need to be able to emulate d2, d3, and d5. For instance, to emulate a d10, you roll a d2 and a d5, and if the d2 comes out as 2, you add 5 to the d5 result. As all of the basic dice are multiples of 2, 3 and 5, with no other prime factors, this is what you require.

Similarly, to create d6, simply roll d2 and d3, and if the d2 is a 2, add 3. To create a d12, do a d6, then add 6 if a d2 is 2. A d4? Roll a d2, then if a second d2 is a 2, add 2.

With a d20, you can easily emulate d2 and d5 (also d4 and d10, which makes some processes easier). This leaves d3 as the only thing needing to be emulated.

This is not a trivial problem, and if no changes may be made to the die, and you need to be able to have absolute results (requiring no judgement calls) without the possibility of an infinite number of rerolls, then it won't be doable with a d20.

That said, there are ways around it.

Modifying the die

This is only reasonable if you only need d2, d4, d6, d8, and d12, but you can modify the die so that the 1 and 20 sides cannot be rolled - this could be achieved by adding mud or some other substance to prevent the die from stopping on 1 or 20. Then, for d3, if the number rolled is between 2 and 7, it's a 1, between 8 and 13, it's a 2, and between 14 and 19, it's a 3. For d2, simply look at whether the number is even or odd.

But this will destroy the d5 emulation.

Judgement call

As described by Thomas Markov in his answer, one could use the triangle shape of the d20 to create a kind of d3 (or d12) rolling mechanism. However, it relies on judgement. That is, you have to decide which corner is furthest from you... or if you can't decide it, you take the one nearest. That creates a situation where one could conceivably take any of three results, should it be a "too close to call" situation.

It looks like it's very close to being a "pointing down" position? Move your head ever so slightly so that the one you want is at the top, or position yourself so that they're equal and then take the one at the bottom.

So long as all players are honest, the system will work fine, of course.

Possibly Infinite Rolls

This one is a little simpler, but has its own drawbacks. Roll the d20. If it's a 19 or 20, roll again. Otherwise, take the value mod 3 (or count how many sixes it takes to get it down to between 1 and 6 - a 15 is subtracted twice (15 -> 9 -> 3), so it's a 2).

This does not rely at all on modifying the die, and is guaranteed to produce a fair d18 (which gives d3 and d6 as ways to read it)... but there's no guarantee that you will stop rolling 19s and 20s. In realistic circumstances, it's highly unlikely that you will get stuck in such a loop for more than a few rolls... but not impossible.

Don't use the d20 as a die

There are other ways to produce a d3 result. As noted by Please stop being evil, with two people choosing numbers, they can be combined in a way that effectively creates randomness. The d20 itself can be used to ensure fairness on this - simply put, the GM chooses 1, 2, or 3. She then positions the d20, while shielding it, so that it shows the chosen number. The player then announces their number (1, 2, or 3), and the GM reveals the d20 value. Add them together, and subtract 3 if the value is above 3.

The same can be done for any d value below 20.

This will feel very random... but people have a tendency to avoid the extremes, so the probabilities won't actually be equal.

A Fairer Version

There is one way that you could conceivably get better fairness without using the d20 as a die. The GM holds the die by the 1 and 20 inside a bag or similar, and the player picks one of the "middle" sides - there are 12 sides that are reasonably accessible (assuming the GM's fingers invariably functionally block the three sides directly adjacent to the 1 and 20. Then use the same approach described in "modifying the die" to determine the d3 result.

In the absence of a bag, you can simply have the player close their eyes... but this requires additional trust, as there's nothing stopping the GM from rotating the die while the player's eyes are closed in order to guide the player's finger to the desired side.

Make a Hole

There is one last approach that could work well, but it requires the ability to alter your surroundings to some degree - You could make a small hole shaped to match the vertex of a d20. You roll without being able to see the result, then guide the die to the hole, so that it slots in, before looking. The vertex at the top can work as a d12 (as described by Thomas Markov in their table), which enables you to also emulate a d6, and thus you have all dice doable with the d20.

\$\endgroup\$
2
  • \$\begingroup\$ Modifying it to not be able to roll 1 or 20 would probably bias towards the faces that border on those, not uniformly to all other faces. More importantly, if you're playing an RPG like D&D 5e, you need to still be able to roll it as a d20 very often! (Or you'd have to emulate a d20 in terms of what you can still roll.) \$\endgroup\$ Oct 3, 2020 at 4:40
  • \$\begingroup\$ @PeterCordes - that's precisely why I specified that it's only okay if you're not after one of the multiple-of-5 dice. Note that I speak of using it for d2 and d3 emulation, and that you then combine results from there - while there will be bias in the result if you treat it like a d18, there should be d2 and d3 symmetries in the probabilities, due to how the faces are arranged. This would only fail if, say, you had a die with all of the multiples of 3 directly adjacent to the 1 and 20. \$\endgroup\$
    – Glen O
    Oct 4, 2020 at 10:01
1
\$\begingroup\$

Over a series of rolls Arithmetic coding requires on average the fewest real rolls per emulated roll. The basic idea is that every possible outcome from the real rolls as well as every possible outcome from the emulated rolls are mapped to a range of real numbers between 0 and 1; with the width of each range being equal to that outcome's probability. Note that we can save D20 rolls by just emulating the sum for each multi-die roll. In order to use simpler fractions: after each emulated roll we re-map both sets of ranges so that the outcome of the last roll is expanded to the range 0-1. For example if we want to emulate the rolls D6 and then a 3D8:

D6 ranges:
1: 0 - 1/6
2: 1/6 - 1/3
3: 1/3 - 1/2
4: 1/2 - 2/3
5: 2/3 - 5/6
6: 5/6 - 1
We roll a 6 on the D20, the range we are looking at is now 3/10 - 7/20.
The remaining possibilities on the emulated D6 roll are:
2: 1/6 - 1/3
3: 1/3 - 1/2
We roll a 14 on the D20. The range we are looking at is now 67/200 - 27/80.
The result is 3.

Now we begin emulating 3D8:
After remapping: the range we are looking at is 1/100 - 1/40
3D8 ranges:
3: 0 - 1/512
4: 1/512 - 1/128
5: 1/128 - 5/256
6: 5/256 - 5/128
7: 5/28 - 35/512
8: 35/512 - 7/64
9: 7/64 - 21/128
10: 21/128 - 15/64
11: 15/64 - 81/256
12: 81/256 - 13/32
13: 13/32 - 1/2
14: 1/2 - 19/32
15: 19/32 - 175/256
16: 175/256 - 49/64
17: 49/64 - 107/128
18: 107/128 - 57/64
19: 57/64 - 477/512
20: 477/512 - 123/128
21: 123/128 - 251/256
22: 251/256 - 127/128
23: 127/128 - 511/512
24: 511/512 - 1
Since the remapped range after the last roll is narrower than 0-1; we
can already eliminate most of the possibilities. The remaining ones are:
5: 1/128 - 5/256
6: 5/256 - 5/128
We roll a 19 on the D20.
The range we are looking at is now 97 % 4000 :- 1 % 40
The result is 6
If we emulate another roll: the we can remap the current range to 151/625 - 7/25

Using this method: an individual emulated roll may require more D20 rolls than some of the other methods; but other rolls in the same sequence will require fewer or none.

\$\endgroup\$
0
\$\begingroup\$

It is possible to emulate a full dice set using only fixed number of rolls, but not with a d20.

If you wish to emulate a full dice set using a fixed number of rolls, you need 3 dice. The required dice are: a d10, a d6, and a 2d or "coin". You can omit the "coin" from the required dice if you are willing to use an even/odd result from the d10 or d6. However, omitting the coin does not decrease the number of rolls needed.

To use any two smaller die to emulate a bigger die, the formula is:

dX = (dA * B) - (dB - 1)
where X = A * B

Starting with only a d2 or "coin". You can emulate a d4 by doing two dice rolls:

d4 = (d2 * 2) - (d2 - 1)

You can confirm the results for yourself using this anydice link.

Using this formula, we can produce the following dice in 2 rolls:

d12 = (d6 * 2) - (d2 - 1)
d20 = (d2 * 10) - (d10 - 1) 
   or (d10 * 2) - (d2 - 1)
d100 = (d10 * 10) - (d10 - 1)

You can see that the d10 is required here, as the number of faces on both the d20 and the d100 are not divisible evenly by 6.

Lastly the d8, which requires 3 rolls in total since we have to emulate the d4 as shown above:

d8 = ((d4) * 2) - (d2 - 1)
where d4 = (d2 * 2) - (d2 - 1)

For further details about why this cannot be done using only a d20, please see this excellent answer by ADdV

\$\endgroup\$
4
  • 1
    \$\begingroup\$ This doesn’t answer the question. \$\endgroup\$ Sep 30, 2020 at 21:43
  • \$\begingroup\$ Hi Thomas. I realise I don't directly address the title of OP's question. When I answered the question, there were already several responses which did. However, the OP also asks: "I realize there's an easy way to make due with a single d6 (using the same d6 also for a coin-like mechanic), but I was wondering if this also works with a d20, and what the criteria are for this to work with a dN..." \$\endgroup\$
    – user66244
    Sep 30, 2020 at 22:02
  • \$\begingroup\$ Add multiple dice to the question goes beyond answering what you can do with any single dice. \$\endgroup\$
    – chepner
    Oct 1, 2020 at 13:44
  • \$\begingroup\$ Welcome to RPG.SE! Take the tour if you haven't already, and check out the help center for more guidance. \$\endgroup\$
    – V2Blast
    Oct 2, 2020 at 9:40
0
\$\begingroup\$

disclaimer: I am not a math genius whatsoever and this is not a mathematically correct method.

So my system is simple, say you want to replicate a d4, if you roll your d20 from 1 to 4 you don't have to do anything and you apply the roll as normal.

However if the roll is greater than 4 you subract 16 from it. And if the difference is negative you roll again until that difference is positive. This method will gain you eventually a random value between 1 and 4.

For a d6 you would subtract 14 if it is greater than 6. For a d8 you would subtract 12 if the number is greater than 8. For a d10 you would subtract 10 if the humber is greater than 10. For a d12 you subract 8 if the number is greater than 12.

You could also use this system to replicate other odd die such as a d15 or a d13 as long as you subtract any result above the die number by it's difference from 20.

Happy Rolling!

\$\endgroup\$
-2
\$\begingroup\$

You want a d2? Roll a d20. Odd numbers are 2, anything else is 1.

Want a d3? Roll a d20. If it's 1, 2 or 3 - keep the number. If it's greater than 3 - reroll, until you get something between 1 and 3.

Want a D4? Roll a d20. If it's 1, 2, 3 or 4 - keep the number. If it's greater than 4 - reroll, until you get something between 1 and 4.

You want a d5? Roll a d20...

You see the pattern. No orientations, no gimmicky methods. Rerolling takes 2 seconds - don't make your life harder

\$\endgroup\$
2
  • \$\begingroup\$ A method that can take theoretically infinite rolls is not ideal as requested. \$\endgroup\$ Jan 14, 2021 at 13:01
  • \$\begingroup\$ Why would you ever reroll when emulating a d4/d5? \$\endgroup\$
    – Anagkai
    Jan 14, 2021 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .