use strict; use Data::Dumper; $Data::Dumper::Indent = 1; my @array=qw(a b c d e); my $num = 13; my %result; for (1..$num){ $result{$array[int(rand(scalar(@array)))]}++; } foreach (@array) { print $_, ' => ', $result{$_} ? $result{$_} : 0, "\n"; } ___OUTPUT___ (maybe) a => 2 b => 3 c => 4 d => 2 e => 2
In reply to Re: Seek one liner for distributing an integer
by pelagic
in thread Seek one liner for distributing an integer
by johnnywang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |