SyntaxBomb - Indie Coders

Languages & Coding => SmallBASIC => Topic started by: bplus on November 03, 2019, 03:38:54 PM

Title: Shruffle
Post by: bplus on November 03, 2019, 03:38:54 PM
An updated version for the old line numbered scramble:
Code: [Select]
' shruffle.bas SmallBASIC 0.12.13 (B+=MGA) 2019-11-03
randomize timer
while 1
  cls
  input "Enter a word or phrase to shruffle ";shruffleMe
  shruffleMe = str(shruffleMe) 'make sure we are working with a string
  if shruffleMe <> "" then shruffle shruffleMe :  ? shruffleMe else end
  pause 3
wend

sub shruffle(byref s) 'shuffle letters in string s
  for i = len(s) to 2 step -1 'using F-Y algo for shuffle
    r = int(i * rnd) + 1 : si = mid(s, i, 1)
    mmid s, i, 1, mid(s, r, 1)
    mmid s, r, 1, si
  next
end

sub mmid (byref source, position, length, new)
    s = mid(source, 1, position - 1) + mid(new, 1, length) + mid(source, position + length)
end sub

SimplePortal 2.3.6 © 2008-2014, SimplePortal