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 upA fix for seeding the rng under older win GCC #11305
Conversation
KA101
self-assigned this
Feb 18, 2015
KA101
reviewed
Feb 19, 2015
| static_cast<unsigned>(djb2_hash(reinterpret_cast<unsigned char const*>(seed)))); | ||
| if (!seed) { | ||
| // std::random_device returns the same sequence on older version of GCC on windows. | ||
| random_generator.seed(time(nullptr) ^ 0xDEADBEEF); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bkentel
Feb 20, 2015
Author
Contributor
It was @DavidKeaton -- I would probably have just used time() by itself otherwise. But no worries.
KA101
removed their assignment
Feb 19, 2015
KA101
self-assigned this
Feb 19, 2015
This comment has been minimized.
This comment has been minimized.
|
Can't test this whilst GCC refuses to compile, sorry I didn't make that clear. |
KA101
assigned
KA101
and unassigned
KA101
Feb 19, 2015
kevingranade
reviewed
Feb 20, 2015
| @@ -39,6 +39,7 @@ int main(int argc, char *argv[]) | |||
| #endif | |||
| bool verifyexit = false; | |||
| bool check_all_mods = false; | |||
| bool explicit_seed = false; | |||
This comment has been minimized.
This comment has been minimized.
kevingranade
Feb 20, 2015
Member
The old flow where there was a seed string that was set and then passed to the seeding function was preferable.
kevingranade
reviewed
Feb 20, 2015
| // std::random_device returns the same sequence on older version of GCC on windows. | ||
| random_generator.seed(time(nullptr) ^ 0xDEADBEEF); | ||
| } else { | ||
| random_generator.seed(std::hash<std::string> {}(seed)); |
This comment has been minimized.
This comment has been minimized.
kevingranade
reviewed
Feb 20, 2015
| categories.insert( std::pair<std::string, int>(category, hash) ); | ||
| auto const hash = static_cast<int>(std::hash<std::string> {}(text)); | ||
| snippets.insert( make_pair(hash, text) ); | ||
| categories.insert( make_pair(category, hash) ); |
This comment has been minimized.
This comment has been minimized.
kevingranade
Feb 20, 2015
Member
I don't even know what you're thinking, the build is broken and you're screwing around with random code that works fine already.
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 20, 2015
Contributor
@bkentel Just as a note: the hash of the snippet is stored in the saves along the item data, so a player always sees the same snippet when they look at the item description. Changing the hash function will have a negative effect on save compatibility.
This comment has been minimized.
This comment has been minimized.
bkentel
Feb 20, 2015
Author
Contributor
@BevapDin Good information to have. A comment should probably be added to djb2_hash to indicate that its removal is basically only prevented by this.
This comment has been minimized.
This comment has been minimized.
kevingranade
via email
Feb 20, 2015
Member
KA101
closed this
Feb 20, 2015
DavidKeaton
reviewed
Feb 20, 2015
| static_cast<unsigned>(djb2_hash(reinterpret_cast<unsigned char const*>(seed)))); | ||
| if (!seed) { | ||
| // std::random_device returns the same sequence on older version of GCC on windows. | ||
| random_generator.seed(time(nullptr) ^ 0xDEADBEEF); |
This comment has been minimized.
This comment has been minimized.
DavidKeaton
Feb 20, 2015
Contributor
I think this was in reference to my xor comment on seed initialization.
bkentel commentedFeb 18, 2015
djb2_hash.