replicant4 has asked for the wisdom of the Perl Monks concerning the following question:

hi to all . I have a qustion which might sound easy. I have an array called (@sites) which contains in $sites object. I compare it with another array, and get a certain number of values. Because I want to test the significance of my results, I need to shuffle my @sites, a number of times (say n number) in order to generate random sets of data. that means to change the position of $sites within @sites. How can I do that ? Thanks in advance for everyone's help .

Replies are listed 'Best First'.
Re: bootstrapping an array.
by davido (Cardinal) on Oct 22, 2004 at 15:26 UTC

    You want a Fisher-Yates shuffle. It is also found as part of the List::Util module. I'm sure if you Super Search the Monastery you'll find it spelled out here too.

    For the highest degree of randomness, you just shuffle the list once. This shuffle isn't like shuffling a deck of cards, where you have to do it three or more times to get randomness. The only time you would shuffle more than once is if you have already used the shuffled list, and now need a newly randomized list.


    Dave

Re: bootstrapping an array.
by Mutant (Priest) on Oct 22, 2004 at 14:21 UTC
    This may be of use...
Re: bootstrapping an array.
by pelagic (Priest) on Oct 22, 2004 at 14:23 UTC