Resetting random seed generator at runtime #1253
Unanswered
giovannizotta
asked this question in
Q&A
Replies: 1 comment
-
Hey, @giovannizotta. Fx does not allow swapping out values after the program has started. One of the design choices it made was that it only does things at startup and then gets out of your way, so it's not able to change or re-instantiate things afterwards. For your use case, you may be able to do this directly: rand/v2.Source is an interface. You can probably write a custom implementation of |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am building a Go application using uber-fx to serve as a backend to a online multiplayer game.
I have a test-only module that is only loaded when the application is running in a component testing environment which provides functions like reset database state, etc.
Recently I centralized all randomness of the application by providing a (configurably seeded)
"math/rand/v2/"
Rand
to the components of the application.I would like to be able to "reset" this object on demand at runtime, for example when a test-only endpoint is called to ensure deterministic reproducibility of tests. Basically, runtime swapping of a "bean". Is this possible in fx, or can you think of another way to achieve this?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions