-> 1999 'Fortune shuffle
-> 2000 B$ = A$
-> 2010 FOR I% = 1 TO 10 ' number of character exchanges to make
-> 2020 U = INT(RND * 3) + 1 ' choose a random character position
-> 2030 S = INT(RND * 3) + 1 ' choose another random character position
-> 2040 E$ = MID$(B$, U, 1)
-> 2050 MID$(B$, U) = MID$(B$, S, 1)
-> 2060 MID$(B$, S) = E$
-> 2070 NEXT I%
-> 2080 RETURN
Well, I haven't tried it (though it looks very like a routine that
someone else posted in this thread way back near the beginning), but
I'll comment on it anyway!
It does ten swaps. For each swap, U can have any value from 1 to 3, with
each being equi-probable, and the same is true for S. So there are nine
different equi-probable decision-tree branches for each swap. Since
there are ten swaps, there are 9^10 (some very large number)
equi-probable branches at the end of the tree.
Going back to the logic of my last message, the question is: Can equal
numbers of these branches generate each of the six possible permutations
of three letters? In other words, is 6 an exact factor of 9^10 ? And the
answer to that question *must* be "no"! All powers of 9 must be odd
numbers, since 2 is not a factor of 9, but all multiples of 6 must be
even.
So I am certain that even this modified Fortune routine cannot produce
*exactly* equal probabilities of occurrence for the six permutations.
However, it may produce probabilities that are exceedingly close to
being equal. 9^10 is such a large number that there are is, for example,
extremely little difference between a probability of 123456/(9^10) and
one of 123457/(9^10). Theoretically, they are different, but it is
unlikely that any experiment of practicable length would show this
difference as a perceptible change of frequency.
So, yes, your modified routine is a lot better than your previous one,
but it still isn't perfect. And it needs to do ten sets of calculations
and swaps. I still prefer my routine, which produces a theoretically
perfect result in just two swaps!
Don't you agree?!
dow
--- PCBoard (R) v15.3 (OS/2) 5
---------------
* Origin: FidoNet: CAP/CANADA Support BBS : 416 287-0234 (1:250/710)
|