This F-Y shuffles the string in-place avoiding the split and join. It might be a bit more efficient, but I haven't benchmarked it.
#! perl -slw
use strict;
sub shuffleStr {
my $len = length $_[0];
my ($tmp, $n);
$n = $_+rand($len-$_)
, $tmp = substr( $_[0], $_, 1)
, substr( $_[0], $_, 1) = substr( $_[0], $n , 1)
, substr( $_[0], $n , 1) = $tmp
for 0 .. $len;
$_[0];
}
my $string = 'the quick brown fox';
print shuffleStr($string) for 1..10;
__END__
C:\test>227145
wconbex ftkuoiqhr
xhe kbquio nfwo tcr
xen iu kwoq rtobhcf
h ftcx wikboqnreou
eoqkxhitfwun ocrb
tbikr nuoqofwxh c e
rhtwi efuc kxobnq o
noit oquxhke bwcfr
qruwoox eftnih kcb
oo qwnfet bcxurih k
C:\test>
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.