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

Is this the best syntax possible? #5

Open
mavavilj opened this issue May 5, 2022 · 3 comments
Open

Is this the best syntax possible? #5

mavavilj opened this issue May 5, 2022 · 3 comments

Comments

@mavavilj
Copy link

mavavilj commented May 5, 2022

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 of rng, which is conceptually not similar to the expected a.mean() or mean(a).

@andreaferretti
Copy link
Owner

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.

@mavavilj
Copy link
Author

mavavilj commented May 5, 2022

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 ?

@andreaferretti
Copy link
Owner

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

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

2 participants