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