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 to resume a PRNG, at a later time deterministically? #1

Closed
clamydo opened this issue Oct 13, 2016 · 3 comments
Closed

How to resume a PRNG, at a later time deterministically? #1

clamydo opened this issue Oct 13, 2016 · 3 comments

Comments

@clamydo
Copy link

clamydo commented Oct 13, 2016

How can I access and save the state in a way, that I can resume the pseudo random number generator at a later time?

@clamydo
Copy link
Author

clamydo commented Oct 13, 2016

As a workaround I've implemented a method for a PcgEngine<IType,...>

impl<Itype, Xtype, MulMix, OutMix> PcgEngine<Itype, Xtype, SpecificSeqStream<Itype>, MulMix, OutMix>
    where Itype: PcgOps + BitSize + Clone,
          Xtype: PcgOps + BitSize,
          MulMix: Multiplier<Itype>,
          OutMix: OutputMixin<Itype, Xtype>,
          SpecificSeqStream<Itype>: Stream<Itype>,
          PcgEngine<Itype, Xtype, SpecificSeqStream<Itype>, MulMix, OutMix>: Rng
{
    pub fn extract_seed(&self) -> [Itype; 2] {
        [self.state.clone(), self.stream_mix.get_stream()]
    }
}

I'm not sure, if your interested in adding something like this also for the other subtypes? In the long run, it would be probably wise to add something like extract_seed() to the SeedableRng trait in the rand crate.

@clamydo
Copy link
Author

clamydo commented Oct 13, 2016

Also see rust-random/rand#84.

@robojeb
Copy link
Owner

robojeb commented Feb 25, 2017

@fkjogu sorry for not getting back to you. These past few months have been a whirlwind involving moving and starting a new job.

I like this idea, I toyed with serializing the generators in the "serde" branch.
If you want to submit a pull request for this I would be happy to include it in the library.

If you don't have time, I will get around to implementing it myself sometime soon hopefully.

clamydo pushed a commit to clamydo/pcg_rand that referenced this issue Mar 14, 2017
This enables to extract the state of the PRNG and resume its state by reseeding.

Issue robojeb#1
clamydo pushed a commit to clamydo/pcg_rand that referenced this issue Mar 14, 2017
@robojeb robojeb closed this as completed Sep 4, 2017
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