From: sabbyxtabby@... (Sabby and Tabby) Date: 2003-03-29T21:25:45+09:00 Subject: Re: Weighted random selection -- how would you do this? "Hal E. Fulton" wrote: > Given: A set of items, each with > an associated integer representing > the relative likelihood that each > item will be selected. > > Write: A method that will select > a random item. def random_weighted(items) total = 0 pick = nil items.each do |item, weight| pick = item if rand(total += weight) < weight end pick end -- Tabby