Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Seek one liner for distributing an integer

by pelagic (Priest)
on Sep 22, 2004 at 12:50 UTC ( [id://392905]=note: print w/replies, xml ) Need Help??


in reply to Seek one liner for distributing an integer

YAP (yet another possibility) making it pretty roughly evenly distributed:
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

pelagic

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://392905]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-29 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found