Dear codemasters,
To start off this thread I pose the question for the following problem:
I design a ProbabilityCalculator in pascal using arrays where long integer n represents the number of randoms generated, p stands for the number of possibilities in one hit (a die offers 6 possibilities). Using the array filled up by the above parameters I want to implement a procedure which calculates the number of hits needed to exhaust all possibilities (p). In other words, How many times do I need to throw the die to hit all six sides. I like to call this value "variance". I use the sequential approach in which the algorithm takes in element by element in a loop (for\while) and turns predifined counters...
Anyhow It seems that this exceeds my capabilities. If any of you have struggled whith such out of interest in probability theory please help me out with some code (any language).
Thank you.
Implementing probability theory
Started by mess1ahh, Oct 11 2009 03:04 AM
4 replies to this topic
#1
Posted 11 October 2009 - 03:04 AM
|
|
|
#2
Posted 11 October 2009 - 04:59 AM
Ummm... from a probability standpoint, your project doesn't make sense as stated. Are you trying to estimate the expected number of tosses required to accumulate all values through empirical data? The reason I ask is because you are not guaranteed that your program will stop.
#3
Posted 12 October 2009 - 04:46 AM
It stops when it has gone through all the elements in the array.
#4
Posted 12 October 2009 - 08:25 AM
Which is not guaranteed to happen. You could, theoretically, roll nothing but '1' forever.
#5
Posted 17 October 2009 - 01:58 AM
Trying to see if I understand the problem that you stated:
What you are trying to do is determine the average number of "rolls" ("hits", "throws", whatever) that it takes for a random number generator to return every possibility from field of "p" possible outcomes. You wish to run this simulation "n" times, storing the resulting number of rolls needed each time in an array element (then you do whatever you want with the data gathered).
If my understanding of your problem is right then coding for a set field width of small size (say 6 for a die) can be done by initially setting each possibility of the field to "false" before each simulation. You can use a chain of OR tests in the loop's conditional statement to determine when to stop the current simulation then reset the possibilities back to "false" for the next simulation. In C++ for instance you could create six "bool" variables (call them "one", "two", "three", etc.), initialize them all to "false", set a variable to "true" once it has been rolled, and continue this way until all of the variables have been changed to "true".
I suppose it would be possible to program for variable field widths, but I'm still new to programming in general so I can't help you there. Though if you were to use a large field (say of 20000 possibilities) you'll be waiting a loooooong time for your program to finish simulating everything.
What you are trying to do is determine the average number of "rolls" ("hits", "throws", whatever) that it takes for a random number generator to return every possibility from field of "p" possible outcomes. You wish to run this simulation "n" times, storing the resulting number of rolls needed each time in an array element (then you do whatever you want with the data gathered).
If my understanding of your problem is right then coding for a set field width of small size (say 6 for a die) can be done by initially setting each possibility of the field to "false" before each simulation. You can use a chain of OR tests in the loop's conditional statement to determine when to stop the current simulation then reset the possibilities back to "false" for the next simulation. In C++ for instance you could create six "bool" variables (call them "one", "two", "three", etc.), initialize them all to "false", set a variable to "true" once it has been rolled, and continue this way until all of the variables have been changed to "true".
I suppose it would be possible to program for variable field widths, but I'm still new to programming in general so I can't help you there. Though if you were to use a large field (say of 20000 possibilities) you'll be waiting a loooooong time for your program to finish simulating everything.


Sign In
Create Account

Back to top









