TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: DAVID WILLIAMS
from: ROBERT FORTUNE
date: 1997-09-28 14:36:00
subject: Scramble

  David,
  I've modified the Fortune subroutine. Let me know what you think.
-Robert
' ------------- CUT HERE ----------------------- CUT HERE ----------------
100 ' scramble tester
102 A$ = "cab"
105 T = 600' number of trials for each routine
110 RANDOMIZE TIMER
120 DIM P$(6), N$(2), C(6), L$(3) 'permutations, names, counts, letters
125 '
130 FOR X = 1 TO 2: READ N$(X): NEXT
140 DATA Williams, Fortune
145 '
150 FOR X = 1 TO 6: READ P$(X): NEXT
160 DATA abc, acb, bac, bca, cab, cba
165 '
167 CLS
170 FOR X = 1 TO 2
175 '
180 FOR Y = 1 TO 6
190 C(Y) = 0' zero counters
200 NEXT Y
205 '
210 FOR Y = 1 TO T
215 '
220 ON X GOSUB 1000, 2000 'perform Williams or Fortune shuffle
225 '
230 FOR Z = 1 TO 6' increment appropriate counter
240 IF B$ = P$(Z) THEN C(Z) = C(Z) + 1: Z = 6
250 NEXT Z
255 '
260 NEXT Y
265 '
270 PRINT N$(X); " routine results:"
280 FOR Y = 1 TO 6
290 PRINT P$(Y); C(Y)
300 NEXT Y
310 PRINT
315 '
320 NEXT X
330 END
335 '
999 ' Williams shuffle
1000 FOR U = 1 TO 3
1010 L$(U) = MID$(A$, U, 1)'put characters into array
1020 NEXT U
1025 '
1030 FOR U = 1 TO 2'choose an unrandomized chr and swap with it
1040 SWAP L$(U), L$(U + INT(RND * (4 - U)))
1050 NEXT U
1055 '
1060 B$ = ""
1070 FOR U = 1 TO 3
1080 B$ = B$ + L$(U)'put shuffled chrs into b$
1090 NEXT U
1100 RETURN
1105 '
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
' ------------- CUT HERE ----------------------- CUT HERE ----------------
 * OLX 2.1 TD * Life is hard, and then we die.
--- 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™.