TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: DAVID WILLIAMS
from: ROBERT FORTUNE
date: 1997-10-02 19:58:00
subject: Scramble

RF> 1999 'Fortune shuffle
RF> 2000 B$ = A$
RF> 2005 LOS% = LEN(BS$)
RF> 2010 FOR I% = 1 TO LOS%   ' number of character exchanges to make
RF> 2020 U = INT(RND * 3) + 1 ' choose a random character position
RF> 2030 S = INT(RND * 3) + 1 ' choose another random character position
RF> 2040 E$ = MID$(B$, U, 1)
RF> 2050 MID$(B$, U) = MID$(B$, S, 1)
RF> 2060 MID$(B$, S) = E$
RF> 2070 NEXT I%
RF> 2080 RETURN
DW>Well, I haven't tried it (though it looks very like a routine that
DW>someone else posted in this thread way back near the beginning), but
DW>I'll comment on it anyway!
DW>It does ten swaps. For each swap, U can have any value from 1 to 3, with
DW>each being equi-probable, and the same is true for S. So there are nine
DW>different equi-probable decision-tree branches for each swap. Since
DW>there are ten swaps, there are 9^10 (some very large number)
DW>equi-probable branches at the end of the tree.
   Actually I was thinking of using the length of the string passed to
   determine the number of exchanges to make.
DW>Going back to the logic of my last message, the question is: Can equal
DW>numbers of these branches generate each of the six possible permutations
DW>of three letters? In other words, is 6 an exact factor of 9^10 ? And the
DW>answer to that question *must* be "no"! All powers of 9 must be odd
DW>numbers, since 2 is not a factor of 9, but all multiples of 6 must be
DW>even.
DW>So I am certain that even this modified Fortune routine cannot produce
DW>*exactly* equal probabilities of occurrence for the six permutations.
DW>However, it may produce probabilities that are exceedingly close to
DW>being equal. 9^10 is such a large number that there are is, for example,
DW>extremely little difference between a probability of 123456/(9^10) and
DW>one of 123457/(9^10). Theoretically, they are different, but it is
DW>unlikely that any experiment of practicable length would show this
DW>difference as a perceptible change of frequency.
  That it may "produce probabilities that are exceedingly close" is good
  enough for me. I like the idea that it has that "randomness" built in!
DW>So, yes, your modified routine is a lot better than  your previous one,
DW>but it still isn't perfect. And it needs to do ten sets of calculations
DW>and swaps. I still prefer my routine, which produces a theoretically
DW>perfect result in just two swaps!
   Yes but only when there are only 3 characters in the string. What
   happens when there are more characters in the string?
DW>Don't you agree?!
   Who me? I'm not known, nor have I ever been known for that type of
   behavior! :)
- Robert
 * OLX 2.1 TD * 8 hours of debugging and my code is finally...unreadable?
--- PCBoard (R) v15.3/M 10
---------------
* Origin: MoonDog BBS þ RIME NetHub Brooklyn,NY (1:278/15)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.