Closed julianmichael closed 8 years ago
Looks great, thanks for the contribution!
Was it necessary to move freeze
out to the companion in order to make this work? Lots of other methods in Distribution
create new distributions (map
for example), so I wouldn't necessarily call that a criteria for moving it.
Oh I see. If you create your own instance of Distributions
with a preset seed, you might accidentally revert back to the one used by object Distribution
because freeze
refers to it explicitly. Makes sense.
It can be useful for the programmer to be able to specify a seed. This isn't possible if ThreadLocalRandom is used as a private val inside of Distribution. I factored it out by parametrizing Distribution over rand and providing a default that is equivalent to the original.
The only incompatilibity this should introduce is with the change of freeze. Because it creates a distribution (i.e., uses rand) its natural place seems to be in the new Distributions class. Otherwise a programmer could accidentally introduce seemingly nondeterministic behavior even with a preset seed.