-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
[enhancement] Safe serialization of RNG providers #598
Comments
Sorry for the delay. It might indeed be useful to have some kind of serialize-like API. Something like |
@WasabiThumb Version 6.1.0 comes with a way to extract the internal state of a rng as an array of numerical values. Based on it you can recreate the very same generator. |
Closing for now since 6.1.0 offers ways to implement such serialization. |
Great stuff! Thanks |
For a project I am working on, I am utilizing
pure-rand
version6.0.2
for it'sxoroshiro128plus
functionality. However, I wanted to be able to serialize the full state to a JSON-compatible and ideally light format for transmission to be reconstructed by the client, for the purposes of a "shared random" that can make random events have predictable outcomes without waiting for a response from the server (I am aware of the pitfalls of this system).I have resorted to accessing the fields
s01, s00, s11, s10
on the object (permalink), which does allow exactly what I wanted. Ideally though, this would be top-level API, as relying on undocumented fields has prevented my project from receiving patches from the upstream. Clarification on whether it's safe to assume these fields won't change would be valuable in the short-term.For reference, here is the relevant code I used for serialization. I am aware that a Uint8Array is a more efficient representation when working with websockets, but for my own sanity and the speed of my project development I've elected for the usage of JSON packets.
(in class PureRandom, where
this.random
is a RandomGenerator)I would make a PR, but the "best" way to serialize an RNG provider is entirely subjective. My hand has been placed on the scales. ;)
The text was updated successfully, but these errors were encountered: