How to use to replace rand()?

后端 未结 5 811
执笔经年
执笔经年 2020-12-28 13:45

C++11 introduced the header with declarations for random number engines and random distributions. That\'s great - time to replace those uses of <

5条回答
  •  自闭症患者
    2020-12-28 14:10

    How about randutils by Melissa O'Neill of pcg-random.org?

    From the introductory blog post:

    randutils::mt19937_rng rng;
    
    std::cout << "Greetings from Office #" << rng.uniform(1,17)
              << " (where we think PI = "  << rng.uniform(3.1,3.2) << ")\n\n"
              << "Our office morale is "   << rng.uniform('A','D') << " grade\n";
    

提交回复
热议问题