News for hackers. Stuff that matters.
Re:How Gaming Got Its Dice (2013) by tzs on Wednesday June 14, 2017 @12:16PM (#14553750)
> There is no intuitive way to extract percentile results from rolling a small number of d6s.

Here is an algorithm for rolling a single decimal digit using on average about 2.19 d6 rolls (which can be done in parallel if you have more than one d6):

  function one_digit
    d = roll()
    while d == 6
      d = roll()
    if roll() <= 3
        return d - 1
    else
        return d + 4
Do this twice to get a percentile. This seems reasonably intuitive to me.
Re:How Gaming Got Its Dice (2013) by tzs on Wednesday June 14, 2017 @12:47PM (#14553957)
The problem of doing the job of a d10 with a d6 can provide a nice illustration of an application of bases other than 10. Might be useful for an elementary school math teacher trying to explain why the kids should learn this stuff.

Write the numbers from 0.0 through 0.9 in steps of 0.1, but write them in base 6, to produce this table:

  dec base 6
  0.0 0.0000
  0.1 0.0333...
  0.2 0.1111...
  0.3 0.1444...
  0.4 0.2222...
  0.5 0.3000
  0.6 0.3333...
  0.7 0.4111...
  0.8 0.4444...
  0.9 0.5222...
Roll a d6 to generate base 6 digits, which you take as the digits of a base6-imal fraction in [0,1). Roll until you have enough digits to determine which [k/10, (k+1)/10) interval it falls in, using the above table as an aid.

In general this can be used to make a table for simulating a dN with a dM, by writing i/N in base M for i = 0 to N-1.

When M is 2 this gives a nice way to simulate a dN with coin flips.

The above can be made easier to use by representing it in a graph instead of a table, where you start at a root node and follow edges labeled by dM values, and the leaf nodes give the dN values.

That would be easy and fast to use.

Re:How Gaming Got Its Dice (2013) by mhink on Wednesday June 14, 2017 @02:34PM (#14554892)
I've never heard of this method before! That's a _really_ nifty trick, thanks for putting it here!
Re:How Gaming Got Its Dice (2013) by tzs on Wednesday June 14, 2017 @09:36PM (#14557324)
Here's another approach you might enjoy. We wish to simulate a dN with a dM. I'll use simulating a d10 (N=10) with a d6 (M=6).

1. let L = a common multiple of N and M. The least common multiple of N and M is a good choice here, so for our example we'll use L = 30.

2. Make a list of the values you are trying to choose from. Repeat each value L/N times, so that the length of the list is L. For our example, L is 30, N is 10, and L/N is three, so our list consists of the values 1 through 10 each repeated 3 times: [1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10].

3. Viewing this list as M chunks of length L/M, select one of the chunks at random via a roll of our dM. For our example that is 6 chunks of length 5. Here is the list again with parenthesis drawn around the 6 chunks: [(1 1 1 2 2) (2 3 3 3 4) (4 4 5 5 5) (6 6 6 7 7) (7 8 8 8 9) (9 9 10 10 10)]

4. Take the chunk selected by the roll of the dM. If all L/M numbers in the chunk are the same, that is the value of our simulated dN roll and we are done. Let's say we've picked the second chunk, (2 3 3 3 4). That contains more than one distinct value, so we go on to step #5.

5. Replace the list with the items from that chunk, each repeated M times. In our example, our new list is [2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4].

6. Go to step #3.

Note that the second time through this is how we chunk the list: [(2 2 2 2 2) (2 3 3 3 3) (3 3 3 3 3) (3 3 3 3 3) (3 3 3 3 4) (4 4 4 4 4)]. 4 of the 6 chunks contain only one distinct value now, so there is a 2/3 chance that we find our d10 value on the second iteration.

If you actually implement this, you don't need to actually make the lists like I did above. You just need a count of how many times each thing appears. So instead of [1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10] you would have [3 3 3 3 3 3 3 3 3 3], meaning you have three '1', three '2', and so on.

To pick the second chunk, you skip 5 items and then take 5. That means we skip all 3 '1's, and 2 of the '2's, and take 1 '2', then all 3 '3's, and 1 '4'. That gives us [0 1 3 1 0 0 0 0 0 0].

BTW, note that this also works for simulating a smaller die with a larger die. For example, simulating a d6 with a d10. There is a really simple way to do that, of course: roll the d10 and discard anything above 6. With that method, you get a d6 output on 6 out of 10 rolls. Let's call this method the trivial method.

If we use the list method as described above, we get a higher output rate. Here is a little table:

  1 1 1 (1)
  1 1 2   111 111 111 111 111 111 112 222 222 222
  2 2 2 (2)
  2 3 3   222 222 222 233 333 333 333 333 333 333
  3 3 3 (3)
  4 4 4 (4)
  4 4 5   444 444 444 444 444 444 445 555 555 555
  5 5 5 (5)
  5 6 6   555 555 555 566 666 666 666 666 666 666
  6 6 6 (6)
On the left, the first 3 columns just show the initial [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6] list (N distinct values each repeated L/N times) broken down into groups of L/M, which is 3 in this case.

If our d10 roll is 1, 3, 5, 6, 8, or 10 we count that as a successful d6 roll of 1, 2, 3, 4, 5, or 6, respectively, because those chunks all have only one distinct value. I've marked those in the table with the resulting d6 value in parenthesis. So, on the first d10 roll we get a d6 value 6 out of 10 times, just like with the trivial method.

Where we beat it is on the next roll. For each chunk that does not yield a d6 value on the first row, I've added the resulting list, grouped into chunks. Note that in all 4 of the possible lists, 9 out of the 10 chunks have only one distinct value, and so 9 out of 10 times the second roll yields a d6 value.

If the second roll fails too, the trivial method will again only succeed 6/10 times on the third roll. Again we beat it, with a 9/10 success rate, and so on.

Re:How Gaming Got Its Dice (2013) by asw001 on Wednesday June 14, 2017 @07:13PM (#14556771)
I created an account to tell you "great job".
Re:How Gaming Got Its Dice (2013) by failrate on Wednesday June 14, 2017 @03:39PM (#14555428)
The implication in the article is that humans will be doing this on the fly. This solution does not fit with that criterion.
Re:How Gaming Got Its Dice (2013) by tzs on Wednesday June 14, 2017 @04:00PM (#14555625)
That's an easy algorithm to do on the fly. Take two d6s that can be distinguished (different color, for example). Call them A and B.

Roll A and B. If A is a 6, reroll A until it is not 6. If B is even, take A as your result. If B is odd, take A+5 as your result. (I changed to use B odd/even instead of B <= 3 because that might be easier for people).

That gives you a number from 1 to 10. Subtract 1 if you need 0 to 9.

If your two d6s cannot be distinguished, take the one that lands leftmost to be A.

Re:How Gaming Got Its Dice (2013) by failrate on Wednesday June 14, 2017 @06:41PM (#14556650)
No. I won't do any of that. Most games already have enough essential complexity that all of its components must be able to be interpreted at a glance. D20s and D10s make this easy and intuitive without requiring an algorithm or mathematical post-process.
Re:How Gaming Got Its Dice (2013) by brians on Wednesday June 14, 2017 @12:24PM (#14553814)
And that's just how old tables often worked.
Re:How Gaming Got Its Dice (2013) by madcaptenor on Wednesday June 14, 2017 @01:42PM (#14554453)
In fact, this takes exactly 11/5 rolls on average: 6/5 rolls to get a non-6, and then 1 more.
Re:How Gaming Got Its Dice (2013) by PhasmaFelis on Wednesday June 14, 2017 @11:14PM (#14557673)
"Intuitive" in this context means "intuitively practical."

Besides which, that may be intuitive to programmers like us, but it's definitely not intuitive to the average person.