TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: RONALD SCHLEGEL
from: ROBERT FORTUNE
date: 1997-08-09 18:04:00
subject: Scramble

RS>Got a question for ya. Anyone know of a routine that will randomly 
scramble a
RS>string?
RS>Example:
RS>A$ = "test"
RS>B$ = (scramble routine)
RS>PRINT B$
RS>..and the output would be something like:
RS>estt
   Ron,
   Here's one way:
' ------------ CUT HERE ----------------- CUT HERE ------------------------
REM This program scrambles the characters in a string
DEFINT A-Z       ' All untyped variables default to type integer
DECLARE SUB Scramble (Word$)
RANDOMIZE TIMER  ' seed random number generator
CLS
PRINT
Word$ = "Mannerism"    ' our word to scramble
Word$ = UCASE$(Word$)  ' make the word all uppercase
PRINT "The original word is: "; Word$     ' print the original string
PRINT
CALL Scramble(Word$)                      ' scramble the string
PRINT "The scrambled word is: "; Word$    ' print the scrambled string
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM This sub accepts a text string in Word$ and scambles the letters      *
REM returning a string of scambled letters that made up the word passed   *
REM to it.                                                                *
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SUB Scramble (Word$)
LOS% = LEN(Word$)       ' the Length Of String passed
FOR I% = 1 TO LOS%
  DO
    SP% = INT(RND * LOS%) + 1  ' swap pointer (into the Word$ string)
  LOOP UNTIL SP%  I%         ' no sense swapping character with self
  Temp$ = MID$(Word$, I%, 1)   ' store this character temporarily
  MID$(Word$, I%, 1) = MID$(Word$, SP%, 1)  ' and do the swap
  MID$(Word$, SP%, 1) = Temp$  ' reassign char from stored temp character
NEXT I%
END SUB
' ------------ CUT HERE ----------------- CUT HERE ------------------------
I used PDS 7.1 so modify as needed. Hope that helps. Good luck!
-Robert
 * OLX 2.1 TD * ..."Bummer!" said Pooh realizing his scanner was fried.
--- 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™.