-
Notifications
You must be signed in to change notification settings - Fork 87
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
CCRandom initializes its own default state in a non reproducible way #350
Comments
Hmm, I don't see a I see your point about reproducibility, but on the other hand when I call What do other programming languages do here? If they have a similar situation? |
Looks like you should call |
i think i didn't make my point very clearly, sorry about that. i didn't mean to suggest using a deterministic seed by default in @bluddy: that was my workaround: i explicitly called |
@nilsbecker it's not possible because it's not exposed in the interface. It's also just one allocation and really not a huge deal IMO. |
@bluddy ah. i thought maybe then indeed there is another unwanted effect of |
we could have a toplevel |
i guess. however, let default_state = ref (Random.get_state ())
let set_state state = default_state := state; Stdlib.Random.set_state state looks ugly but at least a reset would do what one would expect. it's a duplication of effort but i don't see how one could hook into the chain of states that but what should |
This seems confusing, because it depends on whether or not you It seems like we have conflicting requirements here:
I'm not sure we can satisfy both. For the second one we could at least make the |
i would think that not having
would be so surprising to qualify as a bug. there is also
which i think is nice to have and expected but not having it may be less of a problem? [edit: deleted, i think this was not correct. the CCrandom generators mostly require an explicit state argument, so there is no problem. only |
so a solution could be to be explicit that |
I don't know what to think. |
ocaml-containers/src/core/CCRandom.ml
Line 207 in 447df82
here an internal
__default_state
is created with a random seed, which is later used by default in therun
functions. this default state is different from the one in the includedStdlib.Random
module, namelyRandom.default
, afaict. i came across this because i encountered non-reproducible simulation runs.i worked around it by always calling
run ~st:(Random.get_default_state ())
which copies the default state fromStdlib.Random
, which i make sure to initialized in a reproducible way. i think this copying costs performance; a better way would be to create, initialize and later supply my own random state to give to the~st
argument ofrun
.anyway, i don't quite understand why
CCRandom
does not reuse the default state inStdlib.Random
? that way,Random.init
would makeCCRandom.run
with default state reproducible, iiuc.The text was updated successfully, but these errors were encountered: