programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Dice Probability - Nested Loops (No Arrays)

Greenhorn
Posts: 14
1
(I managed to solve the problem on my own after a while)

Bartender
Posts: 2087
44
Welcome to the Ranch!

This way someone might learn something from you.

Ranch Hand
Posts: 147
I had a similar problem a while back (computing probabilities for an arbitrary number of different dice (with arbitrary number of sides), and am interested in how you solved this

Greenhorn
Posts: 4
I could be incorrect (it's been a while since I took probability), but I think each dice could be modeled by a discrete uniform probability mass function (PMF), which would be an array of probabilities. If you want to find the PMF of the sum of the dice rolls, then you have to convolve all the dice PMF's together. To get the probability that you get a particular dice roll sum, evaluate the PMF of the sum of the dice rolls at that value. Maybe these calculations could be optimized to avoid the usage of arrays if you're only looking for the probability of one particular sum at a time, but I'm not sure.

Master Rancher
Posts: 2045
75
You're correct.

But determining the (P)DF (or PMF) is not that easy. It makes for a nice problem though:

Given a Die class, with one member: number of sides, and a List of Dice,
give the PDF of this list. (i.e: for each possible outcome of a throw of all the dice
in the list, what is the chance of this outcome?).

Greetz,
Piet

Jan Hoppmann
Ranch Hand
Posts: 147
My approach seems to be a bit more naïve (and rather long):

Damien Sky
Greenhorn
Posts: 14
1
Here's mine:

Bartender
Posts: 10575
66
Damien Sky wrote:Here's mine:

I fear I've misunderstood the problem then. What probability is it that you're trying to work out?

I was working on the premise that it had something to do with the "sum" (assuming it's actually possible) being either equalled or exceeded in the given number of throws, which is likely to be a fixed value and have very little to do with random numbers at all.

Or are you trying to get the probability returned by a randomised test?

Winston

Piet Souris
Master Rancher
Posts: 2045
75
What Damien does is simply to approach the chances by using the so called 'Monte Carlo'
technique. Throw many times, and note how often you get a certain outcome. Nothing
wrong with that, it is just that we are used to getting exact outcomes in the case of
throwing dice, by simply counting how often we get a certain outcome.
This is not what we call (in Statistics) a 'randomized test'.

Greetz,
Piet

Winston Gutkowski
Bartender
Posts: 10575
66
Piet Souris wrote:What Damien does is simply to approach the chances by using the so called 'Monte Carlo' technique. Throw many times, and note how often you get a certain outcome. Nothing wrong with that, it is just that we are used to getting exact outcomes in the case of throwing dice, by simply counting how often we get a certain outcome.
This is not what we call (in Statistics) a 'randomized test'.

Fair enough, but it's what I meant . Now I understand.

Winston

Damien Sky
Greenhorn
Posts: 14
1
My assignment said to use the Monte Carlo method, so that's why I did that.

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.