Skip to content

Instantly share code, notes, and snippets.

@springaki
Last active December 16, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save springaki/5432350 to your computer and use it in GitHub Desktop.
Save springaki/5432350 to your computer and use it in GitHub Desktop.
class Lottery
def initialize(winners)
@winners = winners
@ary = []
end
def add(name, weight)
@ary += Array.new(weight, name)
end
def winners
winners = []
@winners.times {
winners << @ary.at(rand(@ary.size))
}
winners
end
end
require './lottery.rb'
lottery = Lottery.new(3)
lottery.add("John", 1)
lottery.add("Tom", 2)
lottery.add("Bill", 5)
lottery.add("Woz", 2)
lottery.add("Ken", 10)
lottery.winners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment