-
Notifications
You must be signed in to change notification settings - Fork 3
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
Is this the best syntax possible? #5
Comments
The reason is that I want to be explicit about the RNG that I use, and possibly switch the one in use. Your syntax can only work with an implicit RNG. |
I'm not so experienced with Nim in order to understand how to implement the difference I suggested, but in Python this is done via: https://docs.python.org/3/library/random.html#random.seed So I was just thinking that maybe it's possible to do this kind of object in Nim as well. Perhaps: https://github.com/python/cpython/blob/3.10/Lib/random.py#L103 ? |
What you do in Python is to put a seed for your RNG, which makes the number generation deterministic. But still, you are tied to the default RNG provided by the Python standard library (I think it is a Mersenne twister). If you want to change it, say, to a cryptographically safe RNG, you are out of luck. Moreover, this makes the library inherently thread-unsafe, because RNG generally are mutable, thread unsafe objects, and with the Python design, you have to choose a global one. Making the RNG explicit avoids all these issues |
Is the syntax in some parts of alea the best possible?
I'm finding that it's a bit "odd" to have to write, e.g.:
rng.mean(a)
to get the mean of distribution
a
, because this makes reference to being a method ofrng
, which is conceptually not similar to the expecteda.mean()
ormean(a)
.The text was updated successfully, but these errors were encountered: