artist has asked for the wisdom of the Perl Monks concerning the following question:
$string in the above case should contain approximately 15 'a', 10 'b' and '5' a.$hash->{a} = 30; $hash->{b} = 20; $hash->{c} = 10; my $string; foreach (1..30){ my $element = randomKey($hash); $string .= $element; }
I can always do :
and then select random element from the @array; I am looking for the solution in which I don't need to build a big arraymy @array; foreach $key (keys %{$hash}){ foreach $value($hash->{$key}){ push @array, $key; } }
Thanks
Artist
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Random Hash Key according to key frequency
by jdporter (Paladin) on Dec 04, 2002 at 18:28 UTC | |
by iburrell (Chaplain) on Dec 04, 2002 at 18:38 UTC | |
by adrianh (Chancellor) on Dec 04, 2002 at 18:43 UTC | |
by jdporter (Paladin) on Dec 04, 2002 at 18:42 UTC | |
|
Re: Random Hash Key according to key frequency
by BrowserUk (Patriarch) on Dec 05, 2002 at 00:02 UTC | |
|
Re: Random Hash Key according to key frequency
by traveler (Parson) on Dec 04, 2002 at 21:36 UTC |