I've created the following string manipulation function for randomizing my passed string in Lua:
require "string" require "math" math.randomseed( os.time() ) function string.random( self ) local tTemporary, tNew = {}, {} if not self or self:len() < 5 then return nil end self:gsub( "%a", function( cChar ) table.insert( tTemporary, cChar ) end ) for i = 1, #tTemporary, 1 do local iRandom = math.random(1, #tTemporary) tNew[i] = tTemporary[iRandom] table.remove( tTemporary, iRandom ) end return table.concat(tNew, " ") end
Can this be optimized/more-randomised?