Determining probability for a variable number of results?
From: April (aprilo_at_highland.net)
Date: 02/21/04
- Previous message: Chris \( Val \): "Re: Quick help C++"
- Next in thread: osmium: "Re: Determining probability for a variable number of results?"
- Reply: osmium: "Re: Determining probability for a variable number of results?"
- Reply: Karl Heinz Buchegger: "Re: Determining probability for a variable number of results?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 21 Feb 2004 08:33:51 -0500
What I'm trying to do is create the data for a distribution curve of
outcomes given x number of 6 sided dice. I can produce the total number of
outcomes easily enough, but I am having a problem in determining the number
of individual values. Below is what I have so far.
#include <iostream>
#include <vector>
#include <algorithm>
#define ROLLS 3
#define SIDES 6
typedef unsigned long ulong;
typedef unsigned short ushort;
using namespace std;
int main()
{
static ulong outcomes = 1; // total possible outcomes
const ushort loRange = ROLLS; // lowest possible result
const ushort hiRange = SIDES*ROLLS; // highest possible result
const ushort values = (hiRange-loRange)+1; // range lowest to
highest
vector<ushort> results; // store all possible outcomes
for(int i=0; i<ROLLS; i++) // determine total possible
outcomes
outcomes *= SIDES;
results.resize(outcomes*sizeof(ushort)); // pre-set size of vector
// Rest of code should go here to determine the sum for each possible
// dice roll producing reults in the range loRange-hiRange
// then count the number of times that result is produced and finally
// to divide that count by outcomes to get the probability of that
result.
return 0;
}
How would I go about filling the vector with the proper values. I can solve
it for the above values by nesting three for loops, one for each die roll,
but this doesn't help for an unknown number of die rolls. In the actual
program I would like the user to supply the number of rolls as well as the
number of sides on the die, either by command line options or via windows
controls.
Thanks for your help,
April
- Previous message: Chris \( Val \): "Re: Quick help C++"
- Next in thread: osmium: "Re: Determining probability for a variable number of results?"
- Reply: osmium: "Re: Determining probability for a variable number of results?"
- Reply: Karl Heinz Buchegger: "Re: Determining probability for a variable number of results?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]