TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: RONALD SCHLEGEL
from: DAVID WILLIAMS
date: 1997-09-10 18:57:00
subject: Scramble

-> Got a question for ya. Anyone know of a routine that will randomly
-> scramble a string?
->
-> Example:
->
-> A$ = "test"
->
-> B$ = (scramble routine)
->
-> PRINT B$
->
-> ..and the output would be something like:
->
-> estt
Well...
L% = LEN(A$)
DIM L$(L%)
FOR X% = 1 TO L%
   L$(X%) = MID$(A$,X%,1)
NEXT
RANDOMIZE TIMER
FOR X% = 1 TO L%-1
   SWAP L$(X%), L$(X% + INT(RND * (L% + 1 - X%)))
NEXT
B$ = ""
FOR X% = 1 TO L%
  B$ = B$ + L$(X%)
NEXT
PRINT B$
The lines just after the RANDOMIZE TIMER are a general way to "shuffle"
any array into a random order, just like shuffling a deck of cards.
                          dow
--- PCBoard (R) v15.3 (OS/2) 5
---------------
* Origin: FidoNet: CAP/CANADA Support BBS : 416 287-0234 (1:250/710)

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™.