Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
First, your code would probably be cleaner like this (avoiding the use of variables like $entity1 .. $entity9; that's what arrays are for):
For your probability data, consider each "draw" from @entity to be similar to a roll of the dice. Each roll has equal odds of hitting a given number, and a number can be hit more than once. That means the probability of getting a particular sequence should be equally improbable no matter what the sequence happens to be. It is just as improbable of rolling from slot 1, 2, 3, 4, 5 as it is to roll from slot 1, 1, 1, 1, 1. The probability, therefore, is based on the number of rolls and the number of "sides" (number of entities), not the sequence itself. On the other hand, if you're gathering a total based on the draws, the probability of totals will fall along a bell curve. This is something that D&D players know well: If you roll three six-sided dice, your odds of getting a 3 or an 18 are less than your odds of getting an 11. That's because there are more combinations that could net you the sum of 11 , but only one combination (all sixes) will get you a sum of 18. There's an article about this at wikipedia here: Dice. One thing to remember is that your containers are "ever-full". When you draw (or roll), you're not removing, you're just looking and putting it back. At least that's the way your sample code seems to be handling things. Your question I believe is about the probability of hitting a particular sequence. If you have nine entities, each time you draw you have a 1/9th chance of getting a particular one. Your chances of getting a particular sequence of seven draws from a nine-slot bucket is (1/9)^^7. That means that sub probability() can be as simple as this:
Dave In reply to Re: Sample Probabilities
by davido
|
|