Use hash keys for random ordering.
If a set of items needs to be in a random order, or you need a (pseudo)random subset of timesitems, storing them as hash keys will allow them to be ordered randomly without a call to rand
. The order will remain consistent within a program run as long as no insertions or deletions are made to the hash.
Hash keys can be defined quickly
If the information to be stored/randomized is already in an array, the hash can quickly be created with:
@hash{@array}++;
The values of the hash are not particularly useful here, but then the array elements can be retrieved in a random order with:
@random_ordered_array = keys %hash;