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

[bug]: Random.seed(rng::StableRNGs, seed::Integer) not working properly #29

Closed
Fe-r-oz opened this issue Aug 4, 2024 · 2 comments
Closed

Comments

@Fe-r-oz
Copy link

Fe-r-oz commented Aug 4, 2024

Hi Folks,

We want to use StableRNGs for stable streams but there is the following bug:

Random.Seed! using StableRNGs does not work

This gives me a different answer everytime.

julia> using Random

julia> using QuantumClifford

julia> using StableRNGs

julia> rng = StableRNG(42);

julia> Random.seed!(rng, 729);

julia> random_clifford(2)
X₁ ⟼ - YZ
X₂ ⟼ - XX
Z₁ ⟼ - X_
Z₂ ⟼ - _Z

Random.Seed! using Random works

This is static and fine.

julia> using Random

julia> using QuantumClifford

julia> Random.seed!(42);

julia> random_clifford(2)
X₁ ⟼ - YY
X₂ ⟼ - _Y
Z₁ ⟼ + ZY
Z₂ ⟼ + XX

Thanks for the help!

@ericphanson
Copy link
Collaborator

That code isn’t doing what you think; when you seed an rng object (StableRNGs or otherwise) it only affect that specific rng object. You can’t change the global rng in Julia. So the only way to use StableRNGs is to pass the rng object into functions that accept an rng instead of only allowing the global rng.

I’ll close this issue since we can’t change how that works here but feel free to ask if you have questions, here or on http://discourse.julialang.org/.

@Fe-r-oz
Copy link
Author

Fe-r-oz commented Aug 5, 2024

My bad! Indeed! random_clifford(rng, 2) working nicely!

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