in reply to Random Hash Key according to key frequency
my @thresh; my $total = 0; for ( keys %hash ) { $total += $hash{$_}; push @thresh, [ $total, $_ ]; } my $string; for ( 1 .. 30 ) { my $r = rand $total; my $i = 0; while ( $r > $thresh[$i][0] ) { $i++; } $string .= $thresh[$i][1]; }
jdporter
...porque es dificil estar guapo y blanco.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Random Hash Key according to key frequency
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 |