Merge lp:~widelands-dev/widelands/fix-random-tribe into lp:widelands

Proposed by Shevonar
Status: Merged
Merged at revision: 6933
Proposed branch: lp:~widelands-dev/widelands/fix-random-tribe
Merge into: lp:widelands
Diff against target: 13 lines (+3/-0)
1 file modified
src/wlapplication.cc (+3/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix-random-tribe
Reviewer Review Type Date Requested Status
Tino Approve
SirVer Needs Fixing
Review via email: mp+214451@code.launchpad.net

Description of the change

Proper seeding of std::rand function before selecting random tribe. I am not sure if the time function is available on Windows like this, therefore I would like Tino to test this before merging. Thanks :)

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

A nit:
- Pull the srand initialization into wlapplication (i.e. our 'main' function equivalent) and only do it once. Should we ever want to inject a seed (for testing) it should only be done in one place and this should have the same effect in all your call sites.

review: Needs Fixing
Revision history for this message
Tino (tino79) wrote :

Does compile fine on windows and as far as i can see (small sample size), the distribution of tribes is random.

review: Approve
Revision history for this message
Shevonar (shevonar) wrote :

Thanks for your feedback SirVer, I changed it.
Thanks you Tino for testing on Windows.

I'll merge this now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wlapplication.cc'
2--- src/wlapplication.cc 2014-03-29 16:04:47 +0000
3+++ src/wlapplication.cc 2014-04-07 20:47:36 +0000
4@@ -304,6 +304,9 @@
5 if (SDLNet_Init() == -1)
6 throw wexception("SDLNet_Init failed: %s\n", SDLNet_GetError());
7
8+ // seed random number generator used for random tribe selection
9+ std::srand(time(nullptr));
10+
11 //make sure we didn't forget to read any global option
12 g_options.check_used();
13 }

Subscribers

People subscribed via source and target branches

to status/vote changes: