Quote from: Bayes on December 16, 2014, 10:04:10 AM
Thanks, Teo.
I wrote a similar program a while ago to generate these kinds of stats. There's a classic problem in probability called the "Coupon Collector's Problem":
Given N coupons, how many draws do you have to make before you've drawn each coupon at least once?
Obviously, in a roulette context, the coupons are spins, but you could apply it to streets, double-streets etc, just replace 37 with 12, 6 or whatever.
The program can find the average number of trials in cases where not all coupons are collected, and also the probability that at least X coupons will be collected within Y trials. e.g. The "law of the third" says that roughly 24 unique numbers will hit in 37 trials, but what is the probability that at least 24 numbers will hit in 37 trials?
The program input is:
output:
Or, what is the probability that in 20 spins, at least 8 streets will have shown up?
Input:
Output:
This program was purely for my own use, so it only runs on a Linux command line, but if anyone's interested, here's the code (it would be quite easy to re-write in the language of your choice):Code Select'-----------------------------------------------------------
' Given n coupons, how many coupons do you expect you need
' to draw with replacement before having drawn each coupon
' at least once?
' http://en.wikipedia.org/wiki/Coupon_collector%27s_problem
' The program finds the average number of trials in cases
' where not all coupons are collected, also the maximum
' and minimum number of trials, and the probability that
' at least m coupons will be collected within v trials.
'-----------------------------------------------------------
'xfce4-terminal -H --geometry 90x30 -e @
OPTION BASE 1
'can take a long time for large N.
CONST RUNS = 100000
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim
IF dim < 4 THEN
PRINT "Usage: coupons <m> <n> <v>"
PRINT "m: Number of coupons to be collected (m <= n)"
PRINT "n: Number of coupons in the set."
PRINT "v: Number of trials within which the probability"
PRINT "is P that all coupons are collected."
END
ENDIF
M = VAL(arg$[2])
N = VAL(arg$[3])
V = VAL(arg$[4])
GLOBAL coupons TYPE NUMBER ARRAY N
DECLARE t[RUNS]
trials = 0
sum = 0
class = 0
max_trials = 0
min_trials = 99999
FOR i = 1 TO RUNS
REPEAT
x = RANDOM(N) + 1
INCR trials
INCR coupons[x]
drawn = 0
FOR j = 1 TO N
IF coupons[j] > 0 THEN INCR drawn
NEXT j
IF drawn = M OR drawn = N THEN
t[i] = trials
INCR sum, trials
IF trials <= V THEN INCR class
FOR k = 1 TO N
coupons[k] = 0
NEXT k
' get max & min
IF trials > max_trials THEN
max_trials = trials
END IF
IF trials < min_trials THEN
min_trials = trials
END IF
trials = 0
END IF
UNTIL drawn = M OR drawn = N
NEXT i
p# = class/RUNS
PRINT "Average number of trials needed to collect "
PRINT M, " coupons from a set of ", N, " coupons = ", sum/RUNS + 1
PRINT "Maximum number of trials needed was ", max_trials
PRINT "Minimum number of trials needed was ", min_trials
IF V NE 0 THEN
PRINT "Probability of collecting at least "
PRINT M, " coupons in ", V, " trials = ", 100 * p#, " %\n"
END IF
And I've attached the binary, in case there are any Linux users here.
[attachurl=1]
Teo, I wasn't trying to hijack your thread or steal your thunder, so feel free to delete if you like! (I just thought it seemed like an on-topic contribution).
Would you be willing to share your Labby 1.5 source code? I wanted to make some modifications such as a reverse Labouchere function.