Skip to main content
edited body
Source Link
Xcali
  • 16.2k
  • 2
  • 15
  • 39

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;

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 times, 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;

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 items, 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;
Source Link
Xcali
  • 16.2k
  • 2
  • 15
  • 39

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 times, 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;