-
Notifications
You must be signed in to change notification settings - Fork 68
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
RF: Rename rnd to rng and use instead of seed if applicable. #828
RF: Rename rnd to rng and use instead of seed if applicable. #828
Conversation
I think that one decision we should take is if we want to keep on using the stdlib |
I don’t see that guarantee as a thing we should care about. What would be the long-term use case? |
I don’t see that guarantee as a thing we should care about. What would be the long-term use case?
fix a bug in a bot 10 years after the facts maybe or replay that game at the tournament in Heraklion to your grand-children ;)
|
A reasonable argument for sure, but you’d also need the 10-year old Pelita for that (chances are that we ourselves have changed the order of the calls to rng – this PR already changes it for example) and likely also some old-enough Python to be able to run it. I’m open for changes in case you find the numpy version nicer. Maybe you prefer |
I’m open for changes in case you find the numpy version /nicer/. Maybe
you prefer *rng.integers* to *rng.randint* or you think that it is
useful for the students to get an array of random numbers quickly?
No, I actually think the renaming you just did brings us near enough to
the "accepted" way of doing things. I don't see the advantage to use the
numpy RNG for now.
|
Yeah, if you want, you can now easily plug your own stable RNG. ;)
|
What I like about the numpy style is that it allows one to pass a seed directly to rng and the handling is all done in one line. To do it properly, we have to write
which looks a bit unbalanced. |
806bd4f
to
7fef122
Compare
7fef122
to
c37f331
Compare
I think we can merge this? @otizonaizit The tournament needs some further handling (#833) but this PR gets us half-way there at least. I have kept the In most other cases
We could make this a library function and do it all in a one line assignment (just like numpy does it) but we don’t have a good place where to put it. ( There are some inner functions (mostly the underscore functions in I am inclined to add type annotations |
This is an impressive amount of work, thanks! Two comments/questions before merging:
what does that mean? I think you mean #833 ? I was under the impression that the tournament was already reproducible (in this context reproducible and predictable is the same, or do you mean something different?). What is missing?
That is very useful, yes!
Why not just use everywhere the
OK, agreed!
Very good. We should keep flame wars for in-person meetings ;-) |
Yeah, sorry, that wasn’t super exact. The tournament is (and was) reproducible and now with the rng it is even reproducible in a traceable manner and not just based on the right order of imports.
Yeah, in the end I didn’t want to import numpy just for that function, which is basically just a function of three lines ( https://github.com/numpy/numpy/blob/18507bb9f8f50bac415999f832bcbed0766b1f69/numpy/random/_generator.pyx#L5067-L5075 ) But we can try it. Unfortunately it uses a different algorithm and returns slightly different types.
I’m 60:40 to keeping plain Python in the backend but if you prefer the other I’ll change it (maybe in a separate issue: We would need to discuss whether we also need to change bot.random to the numpy version then). |
Ah yes, now I understand. Cool, #833 isn't a blocker for this PR and it would be a new feature anyway, so all is fine.
I didn't think about the fact the But then just plug the wrapper into |
(I missed a few files apparently. Working on it) |
bd75074
to
bd349cd
Compare
Fine with |
Do you plan to go for |
Should be good to merge then |
RF: Rename rnd to rng and use instead of seed if applicable. 7cf29c1
Renamed
rnd
torng
(which seems to be the numpy accepted name) and changedget_random_layout
to use therng
object instead of the seed.Open question (need to think about it a bit more): How to deal with the seed argument in
setup_game
andrun_background_game
.The big idea is to get away from global random state (either through the
random
module or with cheating viaRNG = random.Random()
). There should be onerng
generator that should be passed around to all functions that rely on it.Closes #827