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

ArgParse modifies global random state? #121

Closed
veddox opened this issue Jan 21, 2023 · 2 comments
Closed

ArgParse modifies global random state? #121

veddox opened this issue Jan 21, 2023 · 2 comments

Comments

@veddox
Copy link

veddox commented Jan 21, 2023

I've just noticed that calling parse_args() changes the state of the GLOBAL_RNG:

julia> using ArgParse, Random

julia> Random.seed!(1)
TaskLocalRNG()

julia> rand()
0.07336635446929285 # <- expected value when seeding the GLOBAL_RNG with 1

julia> Random.seed!(1)
TaskLocalRNG()

julia> s = ArgParseSettings()
ArgParseSettings(
  ...
  )

julia> rand()
0.07336635446929285 # <- this is still correct

julia> Random.seed!(1)
TaskLocalRNG()

julia> parse_args(s)
Dict{String, Any}()

julia> rand()
0.6702639583444937     # <- not the expected value

Is there a reason for this? Since ArgParse doesn't even import Random, I don't understand why this happens, but it's giving me some problems with my own code.

@veddox
Copy link
Author

veddox commented Oct 4, 2023

I think this has to do with a Julia issue, where the state of the RNG is changed when a new task is spawned: JuliaLang/julia#49110

ArgParse does work with tasks (see here), so this is probably the root cause of the issue. If so, it should be fixed with Julia 1.10.

@carlobaldassi
Copy link
Owner

Indeed this was fixed in Julia

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