Created
July 14, 2020 04:24
-
-
Save Kansattica/36a9192fd11443075291cc9b49b8c6ce to your computer and use it in GitHub Desktop.
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
#include <random> | |
#include <iostream> | |
#include <algorithm> | |
#include <array> | |
constexpr int trials = 2000000000; | |
int main() | |
{ | |
constexpr std::array<int, 13> boost_value = { | |
0, // on a 0, no boost | |
1, // 1 | |
1, // 2 | |
1, // 3 | |
2, // 4 | |
2, // 5 | |
2, // 6 | |
2, // 7 | |
3, // 8 | |
3, // 9 | |
3, // 10 | |
3, // 11 | |
4 // 12 | |
}; | |
std::random_device r; | |
std::mt19937_64 rand(r()); | |
std::uniform_int_distribution<int> d8(1, 8); | |
std::uniform_int_distribution<int> d10(1, 10); | |
std::uniform_int_distribution<int> d12(1, 12); | |
double running_average = 0; | |
for (int i = 0; i < trials; i++) | |
{ | |
running_average = ((running_average * (i+1)) + boost_value[std::max( { d8(rand), d10(rand), d12(rand) })]) / (i+2); | |
} | |
std::cout << "Average value over " << trials << " rolls is a +" << running_average << " boost.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment