Skip to content

Instantly share code, notes, and snippets.

@sillykelvin
Last active December 29, 2015 14:49
Show Gist options
  • Select an option

  • Save sillykelvin/7686899 to your computer and use it in GitHub Desktop.

Select an option

Save sillykelvin/7686899 to your computer and use it in GitHub Desktop.

Revisions

  1. @KelvinH KelvinH revised this gist Nov 28, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions main.cpp
    Original 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(rng, dist3, true))
    if(GetIt(eng, dist3, true))
    ++change_sum;
    if(GetIt(rng, dist3, false))
    if(GetIt(eng, dist3, false))
    ++unchange_sum;
    }

  2. @KelvinH KelvinH revised this gist Nov 28, 2013. 1 changed file with 17 additions and 7 deletions.
    24 changes: 17 additions & 7 deletions main.cpp
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    #include <iostream>
    #include <random>

    bool GetIt(std::mt19937& engine, const std::uniform_int_distribution<std::mt19937::result_type>& generator3, bool change) {
    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() {
    std::mt19937 rng;
    rng.seed(std::random_device()());
    std::uniform_int_distribution<std::mt19937::result_type> dist3(1, 3);
    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;

    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;
    }
  3. @KelvinH KelvinH created this gist Nov 28, 2013.
    32 changes: 32 additions & 0 deletions main.cpp
    Original 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;
    }