A quick string randomizer

From BioPerl
Jump to: navigation, search

NigelD destroys the competition with the clever use of splice to kick out a random member of the ever-shortening original index array, along with a judicious copy and reverse of the index array -Ed.


sub perm2 {
    my @a = split('',shift);
    my @i = (0..$#a);
    my @j = @i;
    my @r;
    map {
        push @r, splice(@i, rand($_+1),1);
    } reverse @j;
    return join('',@a[@r]);
}
Personal tools
Namespaces
Variants
Actions
Main Links
documentation
community
development
Toolbox