📌  相关文章
📜  C++中的std :: uniform_int_distribution reset()方法(带示例)

📅  最后修改于: 2021-05-30 09:31:54             🧑  作者: Mango

C++中的junit_int_distribution类reset()方法用于重置此uniform_int_distribution。

句法:

void reset();

参数:此方法不接受任何参数。

返回值:此方法不返回任何内容。

例子:

// C++ code to demonstrate
// the working of reset() function
  
#include 
  
// for uniform_int_distribution function
#include 
  
using namespace std;
  
int main()
{
    int a = 10, b = 100;
  
    default_random_engine generator;
  
    // Initializing of uniform_int_distribution class
    uniform_int_distribution distribution(a, b);
  
    cout << "Next value in uniform_int_distribution: "
         << distribution(generator) << endl;
    cout << "Next value in uniform_int_distribution: "
         << distribution(generator) << endl;
    cout << "Next value in uniform_int_distribution: "
         << distribution(generator) << endl;
  
    // Using reset()
    distribution.reset();
    cout << endl
         << "uniform_int_distribution has been reset."
         << endl
         << endl;
  
    // Now the next value won't be in the previous progression
    // and will be another progression
    cout << "Now next value in uniform_int_distribution: "
         << distribution(generator) << endl;
  
    return 0;
}
输出:
Next value in uniform_int_distribution: 10
Next value in uniform_int_distribution: 21
Next value in uniform_int_distribution: 78

uniform_int_distribution has been reset.

Now next value in uniform_int_distribution: 51

参考: https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution/reset

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”