Okay. I've only got a really old BASIC here, but it does the job:
100 ' scramble tester
102 A$="abc"
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 '
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$ 'so a$ is never changed
2020 FOR U=1 TO 3
2030 S=INT(RND*3)+1 'choose a random position, different from U
2040 IF S=U GOTO 2030
2050 E$=MID$(B$,U,1)
2060 MID$(B$,U)=MID$(B$,S,1)
2070 MID$(B$,S)=E$
2080 NEXT U
2090 RETURN
This little program shows your routine to be disastrously awful! Three
of the possibilities are *never* generated!
Try it!
dow
--- PCBoard (R) v15.3 (OS/2) 5
---------------
* Origin: FidoNet: CAP/CANADA Support BBS : 416 287-0234 (1:250/710)
|