Object subclass: #Lottery
  instanceVariableNames: 'numsPerTicket winningTicket prizes range probDist '
  classVariableNames: ''  poolDictionaries: ''    !

!Lottery class methods !
 
picking: aNat from: anInterval paying: anArray
    ^ super new picking: aNat from: anInterval paying: anArray!

example
    ^ self picking: 7 from: (1 to: 42)
           paying: #(0.0 0.0 0.0 1.0 10.0 1000.0 10000000.0)! !

!Lottery methods !
 
picking: aNat from: anInterval paying: anArray
    (anArray size = aNat)
        ifFalse: [ self error: 'bad array size' ]
        ifTrue: [ numsPerTicket := aNat.
                  prizes := anArray copy.
                  range := anInterval.
                  probDist := UniformDiscrete new: anInterval.
                  winningTicket := WinningTicket new ]!

numsPerTicket
    ^ numsPerTicket!
  
range
    ^ range!
payoffs
    ^ prizes copy!
ticketCost
    ^ 1.0!
winningTicket
    ^ winningTicket copy!

pickWinner
    winningTicket initialize: (probDist pick: numsPerTicket)!

winnings: aTicket
    "EFFECT: return the amount of money won by aTicket"
    | m |
    m := winningTicket matches: aTicket.
    (m = 0) ifTrue: [ ^0.0 ] ifFalse: [^prizes at: m]! !
