in reply to Sampling From a Histogram Distribution
Perhaps the following will be helpful:
use strict; use warnings; use List::Util qw/shuffle/; use Data::Dumper; my ( @array, %histRand ); my %hist = ( apples => 4, oranges => 19, pairs => 10, peaches => 5 ); push @array, ($_) x $hist{$_} for keys %hist; @array = shuffle @array; $histRand{ $array[ rand $#array + 1 ] }++ for 0 .. $#array; print Dumper \%histRand;
Output of a run:
$VAR1 = { 'oranges' => 18, 'peaches' => 5, 'apples' => 4, 'pairs' => 11 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sampling From a Histogram Distribution
by Anonymous Monk on Jan 05, 2014 at 21:42 UTC | |
by Kenosis (Priest) on Jan 05, 2014 at 21:46 UTC |