Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor choice of rand out of Distribution #11

Merged
merged 1 commit into from
Jan 18, 2016

Conversation

julianmichael
Copy link
Contributor

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.

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.
@jliszka
Copy link
Owner

jliszka commented Jan 18, 2016

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.

@jliszka
Copy link
Owner

jliszka commented Jan 18, 2016

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.

jliszka added a commit that referenced this pull request Jan 18, 2016
Factor choice of rand out of Distribution
@jliszka jliszka merged commit 257e6bf into jliszka:master Jan 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants