[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Weighted sampling



Bernie Cosell wrote:
> my @dist ;
> foreach my $i (0 .. $#weights)
> {   push @dist, ($i) x $weights[$i] ; }
> 
> sub sample
> {   return $dist[rand(@dist)] ; }

Yes; that's what I did in the Rand::Passwd module.

-- 
John Porter

Useless use of time in void context.


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe