in reply to biased random number picking
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use Math::Random; my @array = qw( cat dog shark frog chimp seahorse ); my @permuted_index = random_permuted_index( scalar(@array) ); print "Here is your entire set:\n"; print Dumper @array; print "Here is a random pick of two:\n"; print Dumper @array[ splice( @permuted_index, 0, 2 ) ]; print "And another two (unique from 1st two):\n"; print Dumper @array[ splice( @permuted_index, 0, 2 ) ]; print "And the final two:\n"; print Dumper @array[ splice( @permuted_index, 0, 2 ) ];
Sample output:
Here is your entire set: $VAR1 = 'cat'; $VAR2 = 'dog'; $VAR3 = 'shark'; $VAR4 = 'frog'; $VAR5 = 'chimp'; $VAR6 = 'seahorse'; Here is a random pick of two: $VAR1 = 'dog'; $VAR2 = 'shark'; And another two (unique from 1st two): $VAR1 = 'seahorse'; $VAR2 = 'frog'; And the final two: $VAR1 = 'cat'; $VAR2 = 'chimp';
|
|---|