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

Generic gen_seed method #36

Open
GregPlowman opened this issue Apr 5, 2018 · 3 comments
Open

Generic gen_seed method #36

GregPlowman opened this issue Apr 5, 2018 · 3 comments

Comments

@GregPlowman
Copy link
Contributor

I see that gen_seed is a common function for all RNGs in RandomNumbers. It would be useful to able to call gen_seed(rng) and have it return the appropriately sized tuple for that rng. This could make code more generic.
I can't see whether this is currently possible. My workaround has been:

Base.length(::Type{NTuple{N,T}}) where {N,T} = N
seed_length(rng) = length(seed_type(rng))
gen_seed(rng::RandomNumbers.AbstractRNG) = gen_seed(output_type(rng), seed_length(rng))

Not sure if Base.length is the right function to extend here, or if there already exists a function for this.

@sunoru
Copy link
Member

sunoru commented Apr 6, 2018

Actually if you have a rng of type RandomNumbers.AbstractRNG, then it is already randomized with some seed. So gen_seed is basically used internally and users don't need to generate seeds by themselves if they want to use the RNGs provided by this package.

However I also believe it might be helpful to generate seeds manually so that the seeds could be stored for later use. The better way is to implement gen_seed(rng_type::Type{T}) where T<:RandomNumbers.AbstractRNG on the types instead of instances. I will have a try.

@GregPlowman
Copy link
Contributor Author

However I also believe it might be helpful to generate seeds manually so that the seeds could be stored for later use.

Yes, exactly. That is my use case. I want randomly-seeded but reproducible simulations.

The better way is to implement gen_seed(rng_type::Type{T}) where T<:RandomNumbers.AbstractRNG on the types instead of instances.

OK, but also consider adding gen_seed(rng::RandomNumbers.AbstractRNG) = gen_seed(typeof(rng))

@sunoru
Copy link
Member

sunoru commented Apr 6, 2018

OK, but also consider adding gen_seed(rng::RandomNumbers.AbstractRNG) = gen_seed(typeof(rng))

I see, but I don't know if it's OK to adding that because of https://docs.julialang.org/en/stable/manual/style-guide/#Avoid-confusion-about-whether-something-is-an-instance-or-a-type-1

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