use Bytes::Random::Secure; my $rng = Bytes::Random::Secure->new( NonBlocking => 1 ); my %weight = ( apples => 4, oranges => 19, pairs => 10, peaches => 5 ); my %map = ( qw/ apples a oranges o pairs p peaches c / ); my %rmap = reverse %map; my $bag = join '', map { ( $map{$_} ) x $weight{$_} } keys %weight; print $rmap{$rng->string_from($bag,1)}, $_% 8 == 0 ? "\n" : "\t" for 1 .. 100; print "\n";