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

How do I support the crippling diversity of RNGs in the Java/Scala Ecosystem? #1

Closed
jbn opened this issue Nov 10, 2015 · 1 comment
Closed

Comments

@jbn
Copy link
Member

jbn commented Nov 10, 2015

What is the proper default? Are implicit wrapping conversions too expensive?

@jbn
Copy link
Member Author

jbn commented Nov 12, 2015

General Solution

scala.util.Random wraps a java.util.Random. So, it delegates to any class that extends java.util.Random. An implicit conversion can unwrap it with negligible cost. Commons Math3 has a RandomAdapter that extends java.util.Random. Thus, it conforms with scala.util.Random. An additional implicit conversion to a RandomGenerator lets a RandomAdapter-wrapping scala.util.Random work with Commons Math3.

This feels like a damn ugly solution, but it has its pluses. For one, it is unobtrusive to Scala developers. They expect scala.util.Random. And, it works seemlessly with libraries that expect a java.util.Random. Finally, it provide a general pattern for interoperability with libraries that roll their own RNG hierarchies.

For (rough) performance considerations, see: https://github.com/generativists/ImplicitRNGPerfTest

@jbn jbn closed this as completed in 28866d2 Nov 12, 2015
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

No branches or pull requests

1 participant