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

proposal: x/exp/rand: add support for PRNG state serialisation and deserialisation #35886

Closed
kortschak opened this issue Nov 28, 2019 · 4 comments

Comments

@kortschak
Copy link
Contributor

kortschak commented Nov 28, 2019

Background

Being able to serialise and deserialise PRNG state is a useful attribute for systems that are used in numerical simulations and game replay. Currently there is no safe way to save/restore PRNG state in either "math/rand" or "x/exp/rand" (the only way to do this currently would be to perform an unsafe conversion and save/restore that.

Proposal

I'd like to propose that the rand.PCGSource be given binary encoding/decoding methods. With this, users needing to save/restore PRNG state can either create a new rand.Source by directly constructing the rand.PCGSource and calling the Seed method, leaving them holding the value and so being able to use the serialisation methods, or alternatively type-assert to this type. No additional methods would be needed in rand.Source.

@gopherbot gopherbot added this to the Proposal milestone Nov 28, 2019
@mpx
Copy link
Contributor

mpx commented Nov 28, 2019

This might fit into the rework for Go 2 (#21835, #26263).

Cc @robpike @josharian

@robpike
Copy link
Contributor

robpike commented Nov 28, 2019

Seems reasonable to me, and since it's in exp the bar for change is very low. Send a CL?

@kortschak
Copy link
Contributor Author

Happy to do that. What is your preferred serialisation format? Just simple binary? I have been thinking about this for our PRNG package in Gonum where I have been considering including the type since we have more than one, but that seems like overkill for here.

@gopherbot
Copy link

Change https://golang.org/cl/209377 mentions this issue: rand: allow serialization of PRNG state

@golang golang locked and limited conversation to collaborators Nov 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants