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

📅  最后修改于: 2021-05-30 20:21:32             🧑  作者: Mango

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

句法:

void reset();

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

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

例子:

// C++ code to demonstrate
// the working of reset() function
  
#include 
  
// for uniform_real_distribution function
#include 
  
using namespace std;
  
int main()
{
    double a = 10, b = 20.5;
  
    default_random_engine generator;
  
    // Initializing of uniform_real_distribution class
    uniform_real_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: 11.3811
Next value in uniform_int_distribution: 14.8158
Next value in uniform_int_distribution: 12.2991

uniform_int_distribution has been reset.

Now next value in uniform_int_distribution: 17.1281

参考: http://www.cplusplus.com/reference/random/uniform_real_distribution/reset/

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