-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add initRand() with seed based on time #16953
Conversation
## | ||
## The resulting state is independent of the default random number generator's state. | ||
## | ||
## **Note:** Does not work for NimScript or the compile-time VM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about instead honor experimental:vmops:
if experimental:vmops
is passed, it would use it, else would use a fixed seed (ie reproducible builds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well you wouldn't use the random
module if you cared about predictability. Current compilation isn't pure either, IOEffect
procs already exist in VM (though not tagged as such), this would just use a TimeEffect
proc. There's no way to check for that experimental, compileOption
doesn't work for experimentals, compiles(getTime())
is true under when nimvm
even if it doesn't work. Maybe it should be a compile option like --pureVM
or --impureVM
, but even then the entire random
module wouldn't make sense as being pure, other languages have things like RandomEffect
(Idris and I believe some Haskell libraries).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no way to check for that experimental
refs #8644 which is very fixable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyways, this can be fixed in future PR, just leave this comment as un-resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, all the other things I mentioned (including future work i added on top) can be done in followup PR's
I assumed there was a reason for this not existing, but now I'm not sure. This proc saves a
times
import and possible incorrect implementations fromRand
initializations that want to use the current time, but don't want to use the global random state. Is there a reason this only exists forrandomize
?The
randomize
with default time seed isn't tested, so I'm assuming this can't be tested either. Will add changelog entry after possible changes are consideredfuture work
EDIT(timotheecour)
Otherwise, low res means lower quality initRand() (esp for multiple threads which would have their numbers more correlated, etc)
std/private/x
if needed) in 2 places:randomize
could use the upcoming std/sysrand add system random to stdlib by xflywind · Pull Request #16459 · nim-lang/Nimlinks