Anagram

By QuickStep on Jul 20, 2004

Probably already some snippets out there, but somebody asked me to do this so I made it for him, but thought it may be a better idea to upload it here. Basically what it does is scrambles a word/sentence, mixing all letters randomly, usage: $anagram(word)

alias anagram {
  var %w = $len($$1), %t = 1
  while (%w) {
    var %v = $+(%v,$chr(1),$mid($replace($$1,$chr(32),$chr(160)),%t,1))
    dec %w | inc %t
  }
  %w = $len($$1)
  while (%w) {
    var %r = $rand(1,%w), %a = $gettok(%v,%r,1), %n = $+(%n,%a), %v = $remtok(%v,%a,1,1)
    dec %w
  }
  return %n
}

Comments

Sign in to comment.
Typo   -  Jun 25, 2008

omg, lmao, I didnt even notice that. I was looking thru quicksteps snippets and just saw it.

lol

 Respond  
napa182   -  Jun 25, 2008

lol this was posted 4 years ago

 Respond  
Typo   -  Jun 25, 2008

When testing yours, I realized it will return the same exact text it was given if the randomness works out that way. For instance, if you $anagram(is) a few times you will get is returned at some point.

Heres the code I came up with to jumble a word/sentence. It isnt as good looking as yours but seems to work great.

This script also makes sure the spaces dont get placed at the very begginning or end of the sentence where they get lost.

alias jumble {
  :start
  unset %jmln* %jmps %tjm* %bdm %bw
  var %jmln = $len($1), %jmln2 = $len($1), %bw = $replace($1,$chr(32),$chr(127))
  while (%jmln >= 1) {
    var %jmps = $rand(1,%jmln2)
    if ($(% $+ tjm $+ %jmps,2) == $null) {
      if ($mid(%bw,%jmln,1) == $chr(127)) && (%jmps != 1) && (%jmps != $len(%bw)) { var % $+ tjm $+ %jmps $mid(%bw,%jmln,1) | dec %jmln 1 }
      elseif ($mid(%bw,%jmln,1) != $chr(127)) { var % $+ tjm $+ %jmps $mid(%bw,%jmln,1) | dec %jmln 1 }
    }
  }
  while (%jmln2 >= 1) {
    var %bdm = %bdm $+ $(% $+ tjm [ $+ [ %jmln2 ] ],2) 
    dec %jmln2 1 
  }
  if (%bdm != %bw) { return $replace(%bdm,$chr(127),$chr(32)) }
  else { goto start }
}

One of the reasons mine looks so much longer is the check for space placement and that I couldnt call $jumble() from within $jumble() so i used a goto line and reset all variables to start it over for when the output == input . To test these I used this line echoed 100 times to test finctionability.
$jumble(hello this is a test) $jumble(this is) $jumble(test) $jumble(is)

Nice work man.

 Respond  
Hawkee   -  Jul 20, 2004

Thanks for the snippet, glad to see people are using this tool to help others.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.