smol-rs / fastrand

A simple and fast random number generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: add `get_seed` method for `Rng`

aleksanderkrauze opened this issue · comments

I have a use case where I would like to generate new Rng with random seed and do a bunch of tests with it, but be able to get the seed back when my test fails so I can reproduce it. Currently there is no way to get a seed from Rng, other than transmuteing it into u64 which I think currently would work but is very stupid (unless Rng would become #repr(transparent) but I don't think it's a good idea). My workaround was to generate myself a random seed, store it and then create Rng with that seed. However I would argue that this is quite troublesome and could be very well avoided by adding a simple function to Rng.

I therefore propose adding method get_seed (or any other name) for Rng that would get seed from inner Cell and then return it to user. It has even additional benefit that user would get current seed and not the initial, so there is no need to emulate previous random generations.

I would be happy to provide a PR for that feature or here objections to this proposition if there are any.

I would accept a PR to add this.

@taiki-e Are you saying that you would accept that PR from me, or that you would do it?

Nb. I am new to this project and don't quite know who is the maintainer of this library and from whom should I get a blessing. 😉

I meant "if you (or someone) send a PR, I would accept it and merge it".

don't quite know who is the maintainer of this library and from whom should I get a blessing.

I'm one of the maintainers so I can merge your PR and release it.
(FWIW, one of the ways to know who is the maintainer is to look at who merged past PRs and who created past releases.)

Thank you. I will try to create it as soon as possible.