Blizzard / Blizzard/s2client-api
Random seed not released (mac only?)
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 280
- PR merge metrics
- No merged PRs in 30d
Description
HI, I had a problem when running the examples that there were too many dev/random clients run, and I tracked it to the function sc2common, maybe only on mac since it hasn't been reported? . I corrected it and seem to be running fine, but I am not too familiar with git so can someone help me to code review and commit the code, or find a better solution since I'm not an expert in programming =) Thank you in advance.
git diff ->
file sc2common.cc
#endif
+#define NUMBER_OF_RANDOM_GENERATORS 256
namespace sc2 {
+struct RandomGenerator {
+ RandomGenerator() : rd(), mt(rd()) {}
+ std::random_device rd;
+ std::mt19937 mt;
+ };
+
+class RandomGeneratorClass{
+ public: RandomGenerator* getNextGenerator(){
+ ++currentGenerator > NUMBER_OF_RANDOM_GENERATORS-1 ? currentGenerator = 0 : NULL;
+ if(randomGenerators[currentGenerator] == NULL){
+ randomGenerators[currentGenerator] = new RandomGenerator();
+ }
+ return randomGenerators[currentGenerator];
+ };
+ private:
+ RandomGenerator *randomGenerators[NUMBER_OF_RANDOM_GENERATORS];
+ int currentGenerator = 0;
+ };
+
+RandomGeneratorClass RGC;
+
-struct RandomGenerator {
- RandomGenerator() : rd(), mt(rd()) {}
- std::random_device rd;
- std::mt19937 mt;
-};
+
+
+
static std::mt19937& GetGenerator () {
- static TLS_OBJECT RandomGenerator* generator;
- if (!generator)
- generator = new RandomGenerator();
- return generator->mt;
+ return RGC.getNextGenerator()->mt;
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.