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

Unexpected RNG behavior w/seed #39

Closed
RatsRatsRats opened this issue Oct 20, 2017 · 1 comment
Closed

Unexpected RNG behavior w/seed #39

RatsRatsRats opened this issue Oct 20, 2017 · 1 comment

Comments

@RatsRatsRats
Copy link

val seed : Long = 1

// Seeding java produces matches
val r = Random()
r.setSeed(seed)
val firstJava = r.nextGaussian()
r.setSeed(seed)
assert(r.nextGaussian() == firstJava)

// So does EJML directly
r.setSeed(seed)
val firstEJML = SimpleMatrix.random(1, 1, 0.0, 1.0, r)
r.setSeed(seed)
val secEJML = SimpleMatrix.random(1, 1, 0.0, 1.0, r)
assert(secEJML.isIdentical(firstEJML, 1e-20))

// koma w/ EJML backend behaves differently
assertMatrixEquals(randn(1, 1, seed), randn(1, 1, seed))  // fails
@kyonifer
Copy link
Owner

Thanks for the report.

I agree the current behavior of ignoring a seed if its been set to that number before is non-obvious. Having randn(seed=something) always apply is also suboptimal, since it means someone setting the seed when they actually need a random number could lead to a bug where they are getting an identical number out every time. They would then have to pull seed setting randn calls outside of any loop, which is awkward because the seed set call will still generate a random number (since seed setting is done in randn). The right solution here I think is to refactor out to a separate seed function, so that you'd call seed(someNum); randn(5) following the more conventional APIs for rngs.

Doing so should probably be part of #36, which in turn is probably dependent on #38 getting done first, since the current "module" system was just a set of quick hacks using conditional compilation until kotlin supported something better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants