Dice Roller (#61)

On Fri, 06 Jan 2006 18:56:47 -0000, Ruby Q.
[email protected]
wrote:

Time to release your inner nerd.

The task for this Ruby Q. is to write a dice roller.

Well, I’m no D&Der, but I think I’m gonna hand in my solution for this
one
as my first Ruby Q. entry :slight_smile:

Cheers,

On 06/01/06, Jim F. [email protected] wrote:

like:
rand(16)+3 rand(16)+3 rand(16)+3

Okay, that output is bogus. However, it is not rand(16) at all. It’s:

(1…3).inject(0) { |sum, ii| sum + (rand(6) + 1) }

The fact that it is three 6-sided dice rolled is important (and is
perhaps more important in a PRNG) because the weighting is a little
different. With rand(16) + 3 you’re just as likely to get 3 as you are
18. With three rand(6) + 1 values, you’re going to get much closer to a
bell curve than a straight probability line. This is a good thing,
because in D&D, 10 is described as absolutely average and 12 is the
high-end for most people. Adventurers, of course, can go to 18, but even
16 is good. Gandalf would be an 18 INT; Sam might be an 11 INT (INT ==
“intelligence”).

Or, for something more complicated:

roll.rb “(5d5-4)d(16/d4)+3”
31
What is the -4 and the /d4 do?

(5d5-4) => Roll a 5-sided dice 5 times and take the sum, subtract 4.
=> Result will be between 1 and 21.
(16 / d4) => Roll a 4-sided dice and divide 16 by the result.
=> Result will be 4, 5, 8, or 16.
d => Roll a [4, 5, 8, or 16]-sided dice 1-21 times and total.
=> The total result will be between 1 and 336.
+3 => Add three to the result.
=> The final result will be between 4 and 339.

Does the +3 apply to (5d5-4)d(16/d4) or to (16/d4) only, assuming it
matters since I don’t know what this stuff does.

d binds tighter than addition.

A few more things… Feel free to either craft this by hand or an
available lexing/parsing library. Handling whitespace between
integers and operators is nice. Some game systems use d100 quite
often, and may abbreviate it as “d%” (but note that ‘%’ is only
allowed immediately after a ‘d’).

So d100 == d% == d00

Yes.

and

100 == 00

No. d00/d%/d100 all refer to values from 1 to 100. It should be
considered impossible to get a value of 0 from dice. Strictly speaking,
d100 should be a special case simulated where you are rolling two d10
values and treating one of them as the 10s and one of them as the 1s.
Again, it results in a slightly different curve than a pure d100 result
would be. One gaming system developed by Gary Gygax after he was ousted
from TSR in the mid-80s used what he termed d10x, which was d10*d10,
resulting in values from 1 - 100 with a radically different probability
curve than a normal d100.

The “natural” dice created are:

d4, d6, d8, d10, d12, d20

Novelty dice created in the past include:

d30, d100

The latter is quite unwieldy.

Strictly speaking, it is not possible to make a die (polyhedron) with an
odd number of faces, but d5 can be simulated by doing a rounded d10/2 or
d20/4.

-austin

How do you parse 5d6d7?
As (5d6)d7 or 5d(6d7) since there is no “Assoziativgesetz” like (AdB)dC
== Ad(BdC).

All binary operators are left associative, so 5d6d7 is (5d6)d7.

Ruby Q. schrieb:

Huhu.
How do you parse 5d6d7?
As (5d6)d7 or 5d(6d7) since there is no “Assoziativgesetz” like (AdB)dC
== Ad(BdC).

aTdHvAaNnKcSe

On Jan 6, 2006, at 5:04 PM, Sascha A. wrote:

< One gaming system developed by Gary Gygax after he was ousted

from TSR in the mid-80s used what he termed d10x, which was d10*d10,
resulting in values from 1 - 100 with a radically different
probability
curve than a normal d100.

Not only a different curve, but also some values would be
impossible to
get (as 13 and 51)

Na, if you get a 1 on the tens die and a 3 on the ones die, you have
rolled a 13.

James Edward G. II

Moin,

Austin Z. wrote:

No. d00/d%/d100 all refer to values from 1 to 100. It should be
considered impossible to get a value of 0 from dice. Strictly speaking,
d100 should be a special case simulated where you are rolling two d10
values and treating one of them as the 10s and one of them as the 1s.
Again, it results in a slightly different curve than a pure d100 result
would be.

How exactly would those d10s differ from a d100?

< One gaming system developed by Gary Gygax after he was ousted

from TSR in the mid-80s used what he termed d10x, which was d10*d10,
resulting in values from 1 - 100 with a radically different probability
curve than a normal d100.

Not only a different curve, but also some values would be impossible to
get (as 13 and 51)

*Sascha

On 1/6/06, Matthew M. [email protected] wrote:

How do you parse 5d6d7?
As (5d6)d7 or 5d(6d7) since there is no “Assoziativgesetz” like (AdB)dC
== Ad(BdC).

All binary operators are left associative, so 5d6d7 is (5d6)d7.

so 1+2*3 == (1+2)*3 == 9?

Dave

On 06/01/06, Sascha A. [email protected] wrote:

Austin Z. wrote:

No. d00/d%/d100 all refer to values from 1 to 100. It should be
considered impossible to get a value of 0 from dice. Strictly
speaking, d100 should be a special case simulated where you are
rolling two d10 values and treating one of them as the 10s and one of
them as the 1s. Again, it results in a slightly different curve than
a pure d100 result would be.
How exactly would those d10s differ from a d100?

In the same way that 3d6 is different than rand(16)+3. It’s not
necessarily as dramatic a difference, but IME, the incidences of the
very lows (01-19) and very highs (81-00) are not as common as those in
the middle.

One gaming system developed by Gary Gygax after he was ousted from
TSR in the mid-80s used what he termed d10x, which was d10*d10,
resulting in values from 1 - 100 with a radically different
probability curve than a normal d100.
Not only a different curve, but also some values would be impossible
to get (as 13 and 51)

Yes.

-austin

On Jan 6, 2006, at 5:10 PM, James Edward G. II wrote:

get (as 13 and 51)

Na, if you get a 1 on the tens die and a 3 on the ones die, you
have rolled a 13.

I misread. Sorry.

James Edward G. II

In article
[email protected],
Ruby Q. [email protected] writes:

Or, for something more complicated:

roll.rb “(5d5-4)d(16/d4)+3”
31

What’s the execution order in this case?
Do 5d5-4 rolls with 5d5-4 probably different dices having 16/d4 sides
(number of sides calculated for each roll individually) or should one
choose the number of sides once for all rolls?
I guess it doesn’t make much difference but it should be specified…

Morus

On 06/01/06, James Edward G. II [email protected] wrote:

On Jan 6, 2006, at 5:04 PM, Sascha A. wrote:
I wrote:

One gaming system developed by Gary Gygax after he was ousted from
TSR in the mid-80s used what he termed d10x, which was d10*d10,
resulting in values from 1 - 100 with a radically different
probability curve than a normal d100.
Not only a different curve, but also some values would be impossible
to get (as 13 and 51)
Na, if you get a 1 on the tens die and a 3 on the ones die, you have
rolled a 13.

That’s for d%; I was referring to “Cyborg Commando” which had a d10x,
which is (d10)*(d10), making a 1,3 combination 3 always. You’d never get
a prime number larger than 7 under the d10x system.

combo = Hash.new(0)

1.upto(10) { |i|
1.upto(10) { |j|
combo[i * j] += 1
}
}

There are 42 possible values here, and 9 values (6, 8, 10, 12, 18, 20,
24, 30, 40) appear four times each. Four values (4, 9, 16, 36) appear
three times each, 23 values twice each, and 6 values once.

It was a truly fucked up system. I think it’s because he was mad to be
ousted.

-austin

On Jan 6, 2006, at 4:31 PM, Austin Z. wrote:

[great explanation snipped]

resulting in values from 1 - 100 with a radically different
probability
curve than a normal d100.

If the 10’s dice is 3 and the 1’s dice is 1, you get 31.

What do you need to roll to get a 0 and 100?

I could see this working if the dice were 0…9 and you add one to the
final result,
but you said that dice should be 1…x. So do you subtract one from each
digit, then add one to the final result?

Example:

10’s 1’s
1 1 => (1-1)(1-1) => (00)+1 => 1
4 1 => (4-1)(1-1) => (30)+1 => 31
10 10 => (10-1)(10-1) => (99)+1 => 100

Jim

On Jan 6, 2006, at 5:35 PM, Jim F. wrote:

What do you need to roll to get a 0 and 100?

A zero on the tens dice is 10. On the one’s dice, it’s zero. 00 is
100.

James Edward G. II

On Jan 6, 2006, at 5:41 PM, James Edward G. II wrote:

On Jan 6, 2006, at 5:35 PM, Jim F. wrote:

What do you need to roll to get a 0 and 100?

A zero on the tens dice is 10. On the one’s dice, it’s zero. 00
is 100.

That doesn’t jive with what was said earlier. There should be no zero
on the tens dice. Only 1…10.

Jim

On 1/6/06, James Edward G. II [email protected] wrote:

On Jan 6, 2006, at 5:35 PM, Jim F. wrote:

What do you need to roll to get a 0 and 100?

A zero on the tens dice is 10. On the one’s dice, it’s zero. 00 is
100.

Clarification: presented in short, long and practical. :slight_smile:

Short clarification:

Actually, when rolled together, both dice are zero-based. The
double-nought is the only special combination of 00 → 100. When
rolled singly, a d10 has 0 → 10. Rolling a 0 is never possible.

Long clarification:

Normally, a d% is rolled as a combination of a “d100” and a d10.
“d100” is in quotes, because it’s actually just a special d10 – 10
sided die, that is – except the numbers on the “d100” are 00, 10,
20… 90. The numbers on the d10 are 0, 1, 2… 9. Rolling the two
together and adding you have a range from 0…99. However, since the
tables that require a d% roll are normally 1-based (1…100), the
‘double-nought’ – a 00 on the “d100” and 0 on the d10 – is
considered 100, everything else is face value. Some examples:

00 / 5 → 5
10 / 5 → 15
20 / 0 → 20
00 / 0 → 100

Similarly, when asked to roll a d10, the face numbers are 0…9, but
are interpreted as 1…10 by making the 0 a 10 and leaving the other
faces at face value.

All other dice (in my experience) are always interpreted as face value
(the sides being 1-based).

Regarding the probability curve of a d% versus a true d100 (100-sided
die), they are the same. Consider the d100: there are 100 faces, each
with a 1% probability. With a d% roll (“d100” + d10), each integer
between 1 and 100 (again, double-nought counting as 100) is produced
exactly once, and with the same probability. 53 (produced only by 50 +
3) is no more likely than 99 (90 + 9) or 1 (00 + 1). So for all
intents and purposes, a d% is equivalent to a d100.

Practical clarification:

As mentioned above, rolling two ten-sided dice versus rolling a
100-sided dice produce the same distribution (given the method of
combination). Rolling a ten-sided zero-based die then converting 0 to
10 versus rolling a ten-sided one-based die produce the same
distribution. So if you see dM then rand(M) + 1 will produce the
correct distribution. d% counts as d100.

Now if you’ll excuse me, I’m late for an appointment with my dice.
Your die-rolling lesson for the day was brought to you by the numbers
3, 5 and the letter D. :slight_smile:

Jacob F.

1+2*3 == (1+2)*3 == 9?

You may want to review the precedence order again.

     * All binary operators are left-associative.
     * Operator precedence:
              ( )      highest
              d
              * /
              + -      lowest

On Jan 6, 2006, at 6:17 PM, Jacob F. wrote:

Short clarification:

Actually, when rolled together, both dice are zero-based. The
double-nought is the only special combination of 00 -> 100. When
rolled singly, a d10 has 0 -> 10. Rolling a 0 is never possible.

No wonder I don’t play D&D. I don’t think I am smart enough.

What does 0 -> 10 mean. Does it mean a dice can have the
values 0,1,2,3…10?

If so, why is a 0 never possible?

And why does d10 have 0 -> 10 while a d6 has 1 -> 6?

Jim

Hopefully this ASCII art comes through clean:

Parse tree for: (5d5-4)d(16/d4)+3

            _______________ + _______________
            |                               |
    _______ d _______                       3
    |               |
___ - ___       ___ / ___
|       |       |       |

___ d ___ 4 16 ___ d ___
5 5 1 4

On 06/01/06, Jim F. [email protected] wrote:

No wonder I don’t play D&D. I don’t think I am smart enough.

What does 0 → 10 mean. Does it mean a dice can have the
values 0,1,2,3…10?

If so, why is a 0 never possible?

And why does d10 have 0 → 10 while a d6 has 1 → 6?

d10 has size 0…9, generally because of size (the print on them is
typically only large enough to have one decimal digit). 0 is rarely a
useful number in gaming, so it is treated as a 10 result. Therefore
rand(10) + 1 is sufficient to represent d10. When used as d100, you’ll
get the values 00 … 99, but again, 00 is not a useful value so it is
treated as 100. So rand(100) + 1 is sufficient to represent d100.

-austin

On Jan 6, 2006, at 6:35 PM, Jim F. wrote:

Clarification: presented in short, long and practical. :slight_smile:

Short clarification:

Actually, when rolled together, both dice are zero-based. The
double-nought is the only special combination of 00 -> 100. When
rolled singly, a d10 has 0 -> 10. Rolling a 0 is never possible.

No wonder I don’t play D&D. I don’t think I am smart enough.

It’s really my fault. I keep leading you astray.

What does 0 -> 10 mean. Does it mean a dice can have the
values 0,1,2,3…10?

On a ten sided die are printed the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8,
9. I have no idea why it’s zero based. In most rolls for most games
though, 0 is considered 10.

1d10 will be a number between 1 and 10 for this quiz.

When two tens are rolled together for d100, the first is taken as the
tens digit (0-9) and the second as the ones digit (0-9). The special
case is that 00 is considered 100.

Honestly though, I won’t think less of you if you generate a random
number between 1 and 100. :slight_smile:

James Edward G. II