-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various bug fixes and additions to Resource class
Add unit tests
- Loading branch information
Showing
12 changed files
with
456 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* random_utils.cpp | ||
* | ||
* Copyright (C) 2001-2024 Daniel Horn, Benjaman Meyer, Roy Falk, Stephen G. Tuggy, | ||
* and other Vega Strike contributors. | ||
* | ||
* https://github.com/vegastrike/Vega-Strike-Engine-Source | ||
* | ||
* This file is part of Vega Strike. | ||
* | ||
* Vega Strike is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Vega Strike is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <random> | ||
|
||
int randomInt(int max, int min = 0 ) { | ||
std::random_device dev; | ||
std::mt19937 rng(dev()); | ||
std::uniform_int_distribution<std::mt19937::result_type> int_dist(min,max); | ||
|
||
return int_dist(rng); // TODO: test this gets all items | ||
} | ||
|
||
|
||
double randomDouble() { | ||
const int precision = 10000; | ||
std::random_device dev; | ||
std::mt19937 rng(dev()); | ||
std::uniform_int_distribution<std::mt19937::result_type> int_dist(0,precision); | ||
int random_int = int_dist(rng); | ||
return (double)random_int/precision; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* random_utils.h | ||
* | ||
* Copyright (C) 2001-2024 Daniel Horn, Benjaman Meyer, Roy Falk, Stephen G. Tuggy, | ||
* and other Vega Strike contributors. | ||
* | ||
* https://github.com/vegastrike/Vega-Strike-Engine-Source | ||
* | ||
* This file is part of Vega Strike. | ||
* | ||
* Vega Strike is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Vega Strike is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef VEGA_STRIKE_ENGINE_RESOURCE_RANDOM_UTILS_H | ||
#define VEGA_STRIKE_ENGINE_RESOURCE_RANDOM_UTILS_H | ||
|
||
int randomInt(int max, int min = 0 ); | ||
double randomDouble(); | ||
|
||
#endif //VEGA_STRIKE_ENGINE_RESOURCE_RANDOM_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.