1

There are only six types of dice tradtionally. D4, d6, d8, d10, d12, and d20. All but the d10 are based on the platonic solid. The d10 is what's called a 'barrel dice', which can hold any number between 1 and x, as long as x is even. Of course, such dice are sorta impractical, especially with large numbers, thus why they're only used here.

There is a method to get more numbers out of these, but they must always be a dividend of the highest value. Its popular to use the d6 to do a 1-3 roll for instance. D10s and d20s can also do a 1-5 roll. D20s used to be used to make 1-10 rolls before d10s became popular.

This still leaves some numbers open though. 7 being the most infamous, though every prime number above 5 has this problem. You simply can't use these dice to generate any value between 1 and x, and x is a prime number greater than 5. Or is there?

I've long tried to solve this problem by trying to find a d14 (a barrel die like the d10), but those are super rare and expensive. However, I may have just come up with a way using standard die to roll any number between 1 and x. I'm obviously not the first to come up with it, but I've never seen anyone mention this before, except for rolling 1-100.

For a d100, the standard practice is actually to use what's called 'percentile die'. This a set of two d10s, but one is numbered in intervals of 10 rather than single digits. This die gives the 10s place, and the normal d10 gives the 1s place. You can of course use standard d10s instead, as long as they're different colors.

Why not do this with the other numbers? To get a d13 for instance, you could roll a d6 for the 1s place (remember that d6 is often used to generate 1-3), with a second die or even a coin to generate 0-1 for the 10s place.

This opens up all ranges, except those that involve a 7. For the 1s place at least, you could technically roll d14 and just half the result (like with a d6 for 1-3). Clearly 14 is doable with this system. Thus through this sorta complicated procedure, you can generate any range of values between 1 and x all using standard polyhedral dice.

I wonder though, why you never see anyone mention this? Its not uncommon for people to use d6 for 1-3, or standard d10s for 1-100. The latter uses the same strategy as this. Is it really any more complicated? 7 throws a monkey wrench into it all, of course, but it is still technically doable by using this method to generate the 7 digit individually. Does the math not check out? Is there some reason why people don't do this? Its not like you're using d6s to roll a base-5 number, then converting that to a decimal one (which in theory would work also). Is there something wrong with this? Why in all my years have I never seen someone mention this? Its always been a nuisance that you can't generate 7 results with dice, so why does no one offer this as a solution?

  • 6
    For generating an integer between 1 and 7, you could keep rolling a d8 until you get something other than an 8. This is fairly straightforward in my opinion, but there is a small chance of needing to roll many times. – JimmyK4542 Aug 16 '24 at 03:44
  • 1
    The way you describe in order to obtain a d13 doesn't work: if you abide by the rule of using the d6 as a d3, then you just have the uniform distribution on the set ${1,2,3,11,12,13}$. If you abide by the rule of using the d6 as a d6 when d2 rolls 0 and as a d3 when d2 rolls 1, then you have the probability that wieghs $1/12$ each of the numbers in ${1,2,\cdots,6}$ and $1/6$ each of the numbers in ${11,12,13}$. Either way, you'll never roll a 9. – Sassatelli Giulio Aug 16 '24 at 03:52
  • For some reason that didn't cross my mind. Now I feel idiotic. Guess I'm just sick of not having anyway to generate prime numbers higher than 5. Is there really no method? What about the other method I mentioned of converting to a smaller base? its possible to generate all numbers from 0 to 6. If you lower the base, could you then get all numbers? It would be complicated yes, but nothing a chart couldn't fix. Perhaps not too practical at a gaming table, but that's not the reason why I want a d7 roll so badly. –  Aug 16 '24 at 03:59
  • I believe that your question is sufficiently well-focused. But perhaps the close-voters don't like that you're asking two questions: #1. How to generate a uniform number with a range of x? #2. The "Why not do this with the other numbers" stuff. – PM 2Ring Aug 16 '24 at 13:39
  • Nothing's ever enough on this site. Guess I'm permanently banned from here now due to asking 'stupid questions', with no hint at all as to what I need to do to improve them, and any improvement isn't enough anyway; only absolute perfection is acceptable, even the slightest imperfection is inexcusable. –  Aug 16 '24 at 16:37
  • Also, I wasn't asking 'two questions'. I noticed this was more of me just talking about what I 'discovered'. I only tacked on a question to make it appropriate for this site. So there is only one question. There was no reason to block this. Worthless website and mods. –  Aug 16 '24 at 21:52
  • Your question was closed by ordinary users, not mods. And ordinary users can vote to reopen it. Your question is more likely to be reopened if you [edit] it to give it more focus and make it more obvious what your core question is, and what your proposed solution is. That will also make your question more useful for future readers who have a similar question. – PM 2Ring Aug 17 '24 at 02:03

3 Answers3

2

If I roll a set of dice, then the total number of possible outcomes is the product of the number of sides on all the dice, and they all have equal probability.

In order to turn that into a uniform set of results (e.g. to replicate a d7), you need to be able to assign each of those outcomes to the results in a way that each result is given an equal number of outcomes. You can think of this as being like having $K$ bins, and you're putting each of the $N$ various outcomes each with probability $\frac{1}{N}$ into the bins until each bin contains $\frac{1}{K}$ worth of probability.

That means that I can only do this if the number of results I want divides the product of all of the number of sides on the dice evenly. If I'm working with typical dice like (d2, d4, d6, d8, d10, d12, d20) the only prime factors that will show up are 2, 3 and 5, so I can only ever get results that are multiples of those numbers.

It is possible to get any kind of distribution using an idea similar to rejection sampling - if you roll a d8 and re-roll any 8s, then the result you get will be equivalent to rolling a d7, but the number of rolls you might need to use to get a result is unknown (and you could, with zero probability, be re-rolling forever).

ConMan
  • 27,579
  • So the d7 wins again. Guess I'll be looking into d14 dice afterall. Fml... –  Aug 16 '24 at 04:55
  • Also, the 'rejection sampling' doesn't work with all numbers. What do you roll for a d13? a d20 would have to be re-rolled 7 out of 20 times. That's pretty decent odds for a re-roll to come up. Guess I'm stuck working with numbers whose only dividends are 2,3, and 5. –  Aug 16 '24 at 05:53
  • 2
    @user181917 To get a d13, you could roll a d4 and a d10 to make a d40, then reject a roll of 40 to make a d39, then use division to turn that into a d13. For a d17, use a d10 and a d12 to make a d120, reject 120 to make a d119, then use division by 7. – Sophie Swett Aug 16 '24 at 12:24
  • I already thought of that actually, but thanks for the comment anyway. Alternatively thinking it may be wiser just to stick to normal dice ranges. For a d7 btw, I was thinking of using d50, because 7x7=49. –  Aug 17 '24 at 13:31
2

As mentioned by ConMan and JimmyK4542, you can easily generate random integers from a range of size $x$ for any $x$, using rejection sampling. And with a little bit of number theory and simple arithmetic, it's possible to make the probability of re-rolls as small as you want.

The trick is to exploit Euler's theorem

if $n$ and $a$ are coprime positive integers, then $$a^{\varphi(n)} \equiv 1 \pmod n$$

where $\varphi(n)$ is Euler's totient function, which is the number of positive integers less than $n$ which are coprime to $n$. If $n$ is prime, $\varphi(n)=n-1$, and for composite $n$ it's easy to calculate $\varphi(n)$ if you know the factors of $n$.

Now, there may be smaller solutions $d$ for $a^d \equiv 1 \pmod n$, but in such cases, $d$ is a divisor of $\varphi(n)$.

For example, $\varphi(13)=12$, but $10^6 \equiv 1 \pmod {13}$, since $1000000 = 76923 × 13 + 1$

We can use those last equations to generate uniform random numbers from a set of 13, i.e., in the range $[0, 12]$. We roll 6 D10s (preferably of different colours so we can roll them simultaneously) to generate a number $q$ with $0 \le q \lt 1000000$. If all 6 dice come up zero (a one in a million chance), we re-roll. Then we find the remainder $r \equiv q \pmod{13}$. Then $r$ is our desired random number.

Note that $10^{6m} \equiv 1 \pmod {13}$ for any non-negative integer $m$, so we can reduce the probability of re-rolls even further by rolling $6m$ dice simultaneously, but of course that makes the arithmetic more tedious, especially if you're doing it by pen & paper. ;)

We can use the last trick to reduce the re-rolls when simulating a D7 with a D8. Instead of rolling a single D8 and re-rolling with a probability of $1/8$, we roll a pair of D8s to generate a number in $[0,63]$. Re-roll if both dice come up zero, otherwise divide the result by $9$ to get a number in $[0,7]$. Or vice versa: divide the result by $7$ to get a number in $[0,9]$. In fact, you can do both divisions, and you get a pair of independent random numbers, one in each range.


This is a very important topic in computer science. Billions of (pseudo)random numbers are generated every day, and many algorithms need those numbers to be in a specific range. Somewhat surprisingly, the most efficient (and correct!) algorithms for doing this were only developed in the last decade or so. Professor Melissa O'Neill has a good article on this topic here: Efficiently Generating a Number in a Range. That article discusses various algorithms that have been used over the years, including an excellent new algorithm due to Daniel Lemire.

PM 2Ring
  • 5,544
0

I presume that you want equal probability but you don't say it. If you don't need it then use a larger die and take the modulus to the base of your desired range. So for $7$ you might use a $d10$. This would give you the desired range with no rethrows. However, $1, 2, 3$ would be twice as likely as $4, 5, 6, 7$. From now on, I will assume that equal probability (to the same level as we would expect from a simple case).

You could use a cylindrical die with a polygonal cross-section rather like a pencil. Sharpen both ends to remove the tiny chance of it standing on an end. This would give you any range including prime numbers.

You might be able to reduce rethrows by aiming at a slightly higher non-prime target.

For example, for $d13$ you could use a coin toss and a $d8$ to get a number in the range $1$ to $16$ and only rethrow $3$ out of $16$ times.

Back to coins, by using a coin toss to generate one bit of a binary number, you could achieve any range. If the desired range is a power of $2$ then you need no rethrows. Slightly less than a power of $2$ would be reasonable. Slightly more than a power of $2$ would seem bad but it need not be. Let's consider $33$.

A minor problem is that my scheme might generate $0$ which I guess that you don't want. So, we add $1$ to the binary number generated by the tosses.

A range of $33$ needs $6$ tosses and almost half will be too large. However, you can optimise. If the first toss is not $1$ then you already know that the result will be at most $32$ (remember the $+1$); so, no rethrows. If the first toss is $1$ then you need to toss again but as soon as you get another $1$, you give up and rethrow. You will only need to restart in $5$ cases, $HH$, $HTH$, ..., $HTTTTH$-

badjohn
  • 8,854