How to randomize letters in a word According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod.

So, for fun, what would be the shortest function to randomize letter order in a word while keeping the first and the last letter in place?

Here's my stab at it with JavaScript. All whitespace removed it's at 124 130 characters.

function r(w) {
  var l=w.length-1;
  return l&lt;3?w:w[0]+w.slice(1,l).split("").sort(function(){return Math.random()-.5}).join("")+w[l];
}


Shorter JavaScript always welcome.




Edit: length check added. Function should not fail for short words.
Haskell, 110 120 107 characters

import Random
s l=randomRIO(1,length l-2)&gt;&gt;=g.($l).splitAt
g(a:b,c:d)=fmap(a:).s$c:b++d
g(a,b)=return$a++b


An example of a program using this function:

main = getLine &gt;&gt;= s &gt;&gt;= putStrLn