Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upUse CXX11 pseudo-random engine and distributions for all RNG #27062
Conversation
This comment has been minimized.
This comment has been minimized.
|
Just FYI, I'm going to runoff mt19937 vs std::minstd_rand and some of the other options and keep the speed winner. MT is absolutely not necessary for the workload we're throwing at it, but we can go with that one if there's no perf regression from using it. |
jbytheway
reviewed
Dec 11, 2018
|
Thanks for working on this. Now I can cross it off my TODO list :). |
| } | ||
|
|
||
| int dice( int number, int sides ) | ||
| long dice( long number, long sides ) |
This comment has been minimized.
This comment has been minimized.
jbytheway
Dec 11, 2018
Contributor
Why the switch to long? Just because rng takes long arguments? Use of long tends to lead to odd platform-specific issues so I'd prefer to move in the direction of less long, not more (but that's a personal opinion).
This comment has been minimized.
This comment has been minimized.
Muffindrake
Dec 11, 2018
Author
Contributor
Consistency's sake. What the function actually needed was unsigned arguments (and you probably want to be using uint_leastN_t types because that makes the most sense), because there's no reason for any of the parameters or return value to be negative, but hardly any part of the code base cares about writing correct code. Signed types are used willy-nilly like we're in Java land where everything is signed and wraps.
long is 32-bit on MSVC and 64-bit on Linux.
This comment has been minimized.
This comment has been minimized.
kevingranade
Dec 21, 2018
Member
Consistency with what? The rest of the project uses int, unless you have a demonstrable problem that's caused by using int here, this is more likely to break things than to fix anything.
This comment has been minimized.
This comment has been minimized.
Muffindrake
Dec 24, 2018
Author
Contributor
Consistency with the rest of the random number functions (they use long).
Besides, this makes no difference on MSVC (sizeof (long) == sizeof (int)). The only time this is going to cause issues is when the code using the dice function was broken to begin with - a dice roll so big that it would have overflowed an int (which may still be a problem with the current code). As such there is no reason to deny changing it here.
None of the (mostly trivial) uses of this function do anything crazy with large values - changing the signature to longs will not cause any bugs in reasonable code.
src/rng.cpp Outdated
| static std::uniform_real_distribution<double> rng_real_dist; | ||
| static std::normal_distribution<double> rng_normal_dist; | ||
|
|
||
| uintmax_t rng_bits() |
This comment has been minimized.
This comment has been minimized.
jbytheway
Dec 11, 2018
Contributor
Rather than rolling your own implementation here you could use std::uniform_int_distribution<uintmax_t>(0, std::numeric_limits<uintmax_t>::max()). It may be slower, but probably not significantly so.
src/weighted_list.h Outdated
BevapDin
reviewed
Dec 11, 2018
src/color.cpp Outdated
BevapDin
reviewed
Dec 11, 2018
src/rng.cpp Outdated
BevapDin
reviewed
Dec 11, 2018
src/rng.cpp Outdated
This comment has been minimized.
This comment has been minimized.
|
I noticed that Also, what the fuck does astyle want me to do with the indentation there? I already have little tolerance for automatic code formatting tools, but that looks like a bug to me nonetheless. |
This comment has been minimized.
This comment has been minimized.
|
It turned out to be just a missing parenthesis, which would have been caught by the compiler, but astyle assumes that the code is correct. Please run astyle after the code has compiled, if not remove it altogether. |
jbytheway
referenced this pull request
Dec 23, 2018
Merged
Replace shuf with new Catch2 time seeding option #27275
This comment has been minimized.
This comment has been minimized.
This may seem inconsistent, but the committee has good reasons for this design, and we probably shouldn't deviate from it without good reason. It's what C++ devs are accustomed to. It's also how the old |
jbytheway
reviewed
Jan 1, 2019
src/game.cpp Outdated
jbytheway
referenced this pull request
Jan 3, 2019
Merged
Seed mapgen in tests for reproducibility #27416
jbytheway
referenced this pull request
Jan 14, 2019
Merged
Code optimizations reported by static code analysis (2019-01-11) #27539
This comment has been minimized.
This comment has been minimized.
|
What's the holdup on merging this? |
This comment has been minimized.
This comment has been minimized.
|
You haven't supported your decision to switch to a merseinne twister prng, so I need to write a benchmark for it and verify that the slowdown doesnt impact the game, and that means it's on hold since this isn't a priority for me. |
This comment has been minimized.
This comment has been minimized.
I've literally gone through the entire code base and looked at every use of the functions, none of which will break if the signature is changed to glibc's jbtw literally wants this merged now - the blocker is you. |
This comment has been minimized.
This comment has been minimized.
|
So, I'm getting quite tired of this nonsense - let me break this down for you. The current implementation:
This PR (the precise algorithm of choice for the PRNG is irrelevant and could be trivially switched using compile time options, but I'll entertain MT for now):
Crawl has issues with accepting new contributions (they're not welcome unless you're friends with the existing dev team, and frivolous "game philosophy" reasons will be provided to strike you down where you stand), Nethack has had a policy of "one dev may veto any change" (Nethack is dead), CDDA has a lead developer who requires volumes of pages of academically-verified proof to accept any singular technical change to the game, despite almost never bringing any proof saying that the current technical direction is in any way better than the proposed change. Or he will say that and then put the change on hold for 6 months, at which point the original contributor has lost interest and left the project. Unless of course that technical change is brought on by himself, in which case it's mostly just committed. This project has a lot of contributors - one-time contributors. Ostensibly, this is one of the better games out there, so everyone must be dying to work and improve on it every waking minute of the day. They stopped contributing? Clearly RL must have thrown a wrench at them at some point - the development process, which ends at frustrating stone walls erected for the fun of it, not having anything to do with it. Have you considered that you're the reason why this project has massive issues retaining its contributors, despite its premise (a sandbox survival turn-based game) being so great? |
CleverRaven
deleted a comment from
tyrael93
Jan 24, 2019
This comment has been minimized.
This comment has been minimized.
|
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/the-issue-of-kev-jong-un/18526/2 |
kevingranade
added
the
0.D Freeze
label
Jan 29, 2019
ifreund
removed
the
0.D Freeze
label
Mar 8, 2019
ZhilkinSerg
assigned
ZhilkinSerg
and unassigned
ZhilkinSerg
Mar 20, 2019
ZhilkinSerg
closed this
Apr 24, 2019
ZhilkinSerg
added
the
(S5 - OnHold / Stalled)
label
Apr 24, 2019
This comment has been minimized.
This comment has been minimized.
|
Marking as stalled. |
kevingranade
reopened this
Apr 24, 2019
This comment has been minimized.
This comment has been minimized.
|
Ok this just needs some light testing and it's ready to go (please squash it if you merge it). |
ZhilkinSerg
removed
the
(S5 - OnHold / Stalled)
label
Apr 25, 2019
This comment has been minimized.
This comment has been minimized.
|
Jenkins rebuild. |
jbytheway
reviewed
Apr 26, 2019
|
Looking mostly reasonable, but I have a few comments. |
src/rng.cpp Outdated
src/rng.cpp Outdated
src/rng.cpp Outdated
src/rng.cpp Outdated
src/rng.cpp Outdated
src/rng.cpp Outdated
src/weather_gen.cpp Outdated
This comment has been minimized.
This comment has been minimized.
|
Still needs a rebase, I know some actual conflicts have crept in. |
jbytheway
reviewed
Apr 27, 2019
| @@ -265,7 +265,8 @@ void weather_generator::test_weather() const | |||
| const time_point begin = calendar::turn; | |||
| const time_point end = begin + 2 * calendar::year_length(); | |||
| for( time_point i = begin; i < end; i += 200_turns ) { | |||
| w_point w = get_weather( tripoint_zero, to_turn<int>( i ), 1000 ); | |||
| //@todo: a new random value for each call to get_weather? Is this really intended? | |||
| w_point w = get_weather( tripoint_zero, to_turn<int>( i ), rng_bits() ); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Muffindrake
and others
added some commits
Dec 11, 2018
kevingranade
force-pushed the
Muffindrake:rng_stdcxx11
branch
from
f52205b
to
f5a08f3
Apr 27, 2019
This comment has been minimized.
This comment has been minimized.
|
Rebased to latest and squashed a bunch of noisy commits. |
jbytheway
approved these changes
Apr 28, 2019
|
LGTM, but should probably be rebased again to get a full clean test run. |
Muffindrake commentedDec 11, 2018
Summary
SUMMARY: Infrastructure "Use CXX11 pseudo-random engine for all RNG"
Purpose of change
Avoid bias introduced through int -> float -> int bit discard, and potentially terrible PRNG implementations. Have relatively more consistent runtime for RNG code, rather than completely unpredictable rand() runtime. Clean up code.
Describe the solution