[QUIZ] Dice Roller (#61)

M

Matthew D Moss

Resolve precedence before associativity.

So 1+2-3 == (1+2)-3 because + and - have the same precedence.

But 1+2*3 == 1+(2*3) because * has precedence over +.
 
M

Matthew D Moss

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
 
A

Austin Ziegler

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
 
J

James Edward Gray II

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

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.

Egad, I have been extra dumb today, haven't I? I'm very sorry to
keep leading everyone astray. Jacob has it right here, not me.

James Edward Gray II
 
J

James Edward Gray II

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. :)

James Edward Gray II
 
P

Pierre Barbier de Reuille

Austin Ziegler a écrit :
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.

Not in that case ! Very simple : you have 100 possible values, ranging
from 1 to 100 ... each value correspond to a single dice configuration
(it you rool 2 and 5 you get 25 and you have no other way to get 25).
Thus the probability of each value is 1/100 ... and all values are
equiprobable !

And of course you can generalize the result ^^
You want a d1000 ? take 3 d10
You want a d36 ? take 2 d6 and calculate : 6*(d6-1) + d6
You want a d144 ? take 2 d12 : 12*(d12-1) + d12
 
P

Pierre Barbier de Reuille

Morus Walter a écrit :
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

IMO, all the parenthesis must be resolved before going further.
Thus in the example you rool :
5d5
1d4
and the last one with the result of the two computations.

Otherwise, it would be impraticle to do that with real dices (mmmmhh ...)

Pierre
 
B

Bill Kelly

Hehe, sorry, it's too early. I'm just happy because I finally
finished a ruby quiz.

Cya in 40 hours or so... (and hope I'm really computing non-fubar'd
results... :)


Regards,

Bill
 
M

Matthew Moss

If so, why is a 0 never possible?
And why does d10 have 0 -> 10 while a d6 has 1 -> 6?

For the purposes of this quiz, I propose that dice are 1-based. Which
means a d6 has six sides numbered 1, 2, 3, 4, 5 and 6 (ie, 1->6). A
d10 should be 1->10, not 0->10.

There is a bunch of discussion above talking about d10 variants, but
for simplicity, a N-sided die generates values from 1 to N inclusive.=20
That is, rand(N)+1.
 
R

Ross Bamford

On Sat, 07 Jan 2006 01:44:26 -0000, James Edward Gray II

[snip involved dice discussion]
Honestly though, I won't think less of you if you generate a random
number between 1 and 100. :)

Phew :D
 
J

J. Ryan Sobol

Thank you all for pitching in your explanation of dice rollers to non-
D&D players like my self. However, there's a considerable amount of
noise for this post (already) and I'm not 100% confident I could
parse the dice syntax in English let alone ruby. Would it be
possible to summarize this discussion and post it as an addendum at
http://www.rubyquiz.com/quiz61.html ?

~ ryan ~
 
R

Ross Bamford

Hi,

Just to make sure I have the precedence and so on right, I used a loaded
dice that always rolls it's number of sides to write some tests. Since
there's been some discussion over the precedence rules, I'll post them to
maybe compare with others and see if I'm on the right track. Hope that's
within the rules? I've left out broken input ones, since at the moment
mine just 'does it's best' but I might tighten that up yet...

@asserts = {
'1' => 1,
'1+2' => 3,
'1+3*4' => 13,
'1*2+4/8-1' => 1,
'd1' => 1,
'1d1' => 1,
'd10' => 10,
'1d10' => 10,
'10d10' => 100,
'd3*2' => 6,
'5d6d7' => 210, # left assoc
'2d3+8' => 14, # not 22
'(2d(3+8))' => 22, # not 14
'd3+d3' => 6,
'd2*2d4' => 16,
'd(2*2)+d4' => 8,
'd%' => 100,
'2d%' => 200,
'14+3*10d2' => 74,
'(5d5-4)d(16/d4)+3' => 87, #25d4 + 3
}

Cheers.
 
J

James Edward Gray II

Thank you all for pitching in your explanation of dice rollers to
non-D&D players like my self. However, there's a considerable
amount of noise for this post (already) and I'm not 100% confident
I could parse the dice syntax in English let alone ruby. Would it
be possible to summarize this discussion and post it as an addendum
at http://www.rubyquiz.com/quiz61.html ?

Feel free to summarize here, but I generally don't add the discussion
to the quizzes themselves. I like to keep them pretty basic an we
can always go to the archives as needed, I figure.

I did correct the error on the site though. :)

James Edward Gray II
 
M

Matt Lawrence

Not in that case ! Very simple : you have 100 possible values, ranging
from 1 to 100 ... each value correspond to a single dice configuration
(it you rool 2 and 5 you get 25 and you have no other way to get 25).
Thus the probability of each value is 1/100 ... and all values are
equiprobable !

Wimps! REAL gamers roll 100 sided dice (aka Zoccihedron)

-- Matt
Nothing great was ever accomplished without _passion_
 
R

Ross Bamford

This is wrong, the maximum is 339: (25-4)d(16/1)+3.

I don't understand that. I get:

(5d5-4)d(16/d4)+3 = 87
(5d5-4)d(16/d1)+3 = 339

I read the first as 21 rolls (25 - 4) of a four sided (16 / 4) dice plus
3, while the second is 21 rolls (25 - 4) of a 16 sided (16 / 1) dice, plus
3.

Right?
 
R

Robert Retzbach

I don't understand that. I get:

(5d5-4)d(16/d4)+3 = 87
(5d5-4)d(16/d1)+3 = 339

I read the first as 21 rolls (25 - 4) of a four sided (16 / 4) dice
plus 3, while the second is 21 rolls (25 - 4) of a 16 sided (16 / 1)
dice, plus 3.

Right?
(5d5-4)d(16/d4)+3

(5d5-4) is 25 at max
(16/d4) is 16 at max
25d16+3 is 339 at max

qed
 
R

Ross Bamford

Yeah. I got your list wrong then, I thought the number means the
maximum reachable, not what to throw with loaded dice. Sorry.

Oh, I see. I guess it's a standard thing to do to find the maximum? As I
say I'm a rank amateur when it comes to dice so I apologise if I've gone
against the normal way to do things.

I just wanted to be able to predict the result of the expressions, so I
could calculate the expected result to test the operator precedence rules.
With the loaded dice, 5d5 is effectively a (higher-precedence) 5*5. Hope
it doesn't cause confusion.
 
R

Reinder Verlinde

Christian Neukirchen said:
So what are the maximum and minimum values of this?

Notation: [x,y] is any distribution with minimum x and maximum y. I then
get:

(5d5-4)d(16/d4)+3 = (adb = [a,a*b], so 5d5 = [5,25])

([5,25]-4)d(16/d4)+3 = ([x,y] - c = [x-c,y-c])

([1,21])d(16/d4)+3 = (adb = [a,a*b], so d4 = 1d4 = [1,4])

([1,21])d(16/[1,4])+3 = (c/[x,y] = [c/y,c/x] if x and y > 0)

([1,21])d([4,16])+3 = ([a,b]d[c,d] = [a*c,b*d] if a,b,c, and d > 0)

[4,336]+3 = ([x,y] + c = [x+c,y+c])

[7,339]

Reinder
 
G

Gavin Kistner

So what are the maximum and minimum values of this?

Min: (5*1-4)*(1)+3 = 1*1+3 = 5
Max: (5*5+4)*(16/4)+3 = 29*4+3 = 119

The min for ndm is always n, because all dice start at 1.
The max for ndm is n*m.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top