Skip to content
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

A fix for seeding the rng under older win GCC #11305

Closed
wants to merge 2 commits into from

Conversation

Projects
None yet
5 participants
@bkentel
Copy link
Contributor

commented Feb 18, 2015

  • fix seeding as the title says.
  • eliminate djb2_hash.
  • fix a likely old bug where even if a seed was used, the rng would be seeded again anyway.

@KA101 KA101 self-assigned this Feb 18, 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.

Copy link
@KA101

KA101 Feb 19, 2015

Contributor

time not declared in scope, sorry. :-/

This comment has been minimized.

Copy link
@bkentel

bkentel Feb 19, 2015

Author Contributor

Sorry, should be ok now.

This comment has been minimized.

Copy link
@kevingranade

kevingranade Feb 20, 2015

Member

Don't get cute, just init with the value time() returns.

This comment has been minimized.

Copy link
@bkentel

bkentel Feb 20, 2015

Author Contributor

It was @DavidKeaton -- I would probably have just used time() by itself otherwise. But no worries.

@KA101 KA101 removed their assignment Feb 19, 2015

@KA101 KA101 self-assigned this Feb 19, 2015

@KA101

This comment has been minimized.

Copy link
Contributor

commented Feb 19, 2015

Can't test this whilst GCC refuses to compile, sorry I didn't make that clear.

@KA101 KA101 assigned KA101 and unassigned KA101 Feb 19, 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.

Copy link
@kevingranade

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.

// 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.

Copy link
@kevingranade

kevingranade Feb 20, 2015

Member

This is an unrelated change, it has no business being here.

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.

Copy link
@kevingranade

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.

Copy link
@BevapDin

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.

Copy link
@bkentel

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.

Copy link
@kevingranade

kevingranade via email Feb 20, 2015

Member

@KA101 KA101 closed this 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.

Copy link
@DavidKeaton

DavidKeaton Feb 20, 2015

Contributor

I think this was in reference to my xor comment on seed initialization.

This comment has been minimized.

Copy link
@DavidKeaton

DavidKeaton Feb 20, 2015

Contributor

It was worth a try, I liked it. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.