http://www.perlmonks.org?node_id=227152


in reply to Randomise a string of letters

Using the "Randomizing an Array" example from the Perl Cookbook, I threw together the following code. Does this help?
#!/usr/bin/perl -w use strict; my $gStr='This is my string'; my @gStrArr=split('',$gStr); sub fisher_yates_shuffle { my $array = shift; my $i; for ($i = @$array; --$i;) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } fisher_yates_shuffle(\@gStrArr); $gStr=join('',@gStrArr); print $gStr,"\n";