Last active
December 29, 2015 14:49
-
-
Save sillykelvin/7686899 to your computer and use it in GitHub Desktop.
Revisions
-
KelvinH revised this gist
Nov 28, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,9 +24,9 @@ int main() { int change_sum = 0, unchange_sum = 0; long loop = 100000000; for(long i = 0; i < loop; ++i) { if(GetIt(eng, dist3, true)) ++change_sum; if(GetIt(eng, dist3, false)) ++unchange_sum; } -
KelvinH revised this gist
Nov 28, 2013 . 1 changed file with 17 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,10 @@ #include <iostream> #include <random> typedef std::mt19937 EngineType; typedef std::uniform_int_distribution<std::mt19937::result_type> GeneratorType; bool GetIt(EngineType& engine, const GeneratorType& generator3, bool change) { int correct_door = generator3(engine); int first_choice = generator3(engine); @@ -11,12 +14,13 @@ bool GetIt(std::mt19937& engine, const std::uniform_int_distribution<std::mt1993 } else { if(change) return true; else return false; } } int main() { EngineType eng; eng.seed(std::random_device()()); GeneratorType dist3(1, 3); int change_sum = 0, unchange_sum = 0; long loop = 100000000; for(long i = 0; i < loop; ++i) { @@ -27,6 +31,12 @@ int main() { } std::cout << "Testing times: " << loop << std::endl; std::cout << "Always change choice, hit: " << change_sum << ", percentage: " << static_cast<double>(change_sum) / loop << std::endl; std::cout << "Always unchange choice, hit: " << unchange_sum << ", percentage: " << static_cast<double>(unchange_sum) / loop << std::endl; } -
KelvinH created this gist
Nov 28, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #include <iostream> #include <random> bool GetIt(std::mt19937& engine, const std::uniform_int_distribution<std::mt19937::result_type>& generator3, bool change) { int correct_door = generator3(engine); int first_choice = generator3(engine); if(first_choice == correct_door) { if(change) return false; else return true; } else { if(change) return true; else return false; } } int main() { std::mt19937 rng; rng.seed(std::random_device()()); std::uniform_int_distribution<std::mt19937::result_type> dist3(1, 3); int change_sum = 0, unchange_sum = 0; long loop = 100000000; for(long i = 0; i < loop; ++i) { if(GetIt(rng, dist3, true)) ++change_sum; if(GetIt(rng, dist3, false)) ++unchange_sum; } std::cout << "Testing times: " << loop << std::endl; std::cout << "Always change choice, hit: " << change_sum << ", percentage: " << static_cast<double>(change_sum) / loop << std::endl; std::cout << "Always unchange choice, hit: " << unchange_sum << ", percentage: " << static_cast<double>(unchange_sum) / loop << std::endl; }