ProbabilityDistribution subclass: #UniformDiscrete
  instanceVariableNames: 'range size '
  classVariableNames: 'Rand' poolDictionaries: ''  !

!UniformDiscrete class methods !
 
new: anInterval
    (Rand isNil) ifTrue: [Rand := Random new].
    ^ super new initialize: anInterval! !

!UniformDiscrete methods !
 
initialize: anInterval
    range := anInterval.
    size := anInterval size!
 
next
    "ENSURES: result is a random integer in the interval"
    ^ (range first + ((Rand next) * size) \\ size) asInteger!
 
pick: anInteger
    "REQUIRES: anInteger <= size
     ENSURES: result is a new set that contains anInteger
              distinct random integers"
    | s |
    s := Set new.
    [ (s size) < anInteger ]
        whileTrue: [ s add: self next ].
    ^s! !
