当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ std::uniform_int_distribution reset()用法及代码示例


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

用法:

void reset();

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


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

例:

// C++ code to demonstrate 
// the working of reset() function 
  
#include <iostream> 
  
// for uniform_int_distribution function 
#include <random> 
  
using namespace std; 
  
int main() 
{ 
    int a = 10, b = 100; 
  
    default_random_engine generator; 
  
    // Initializing of uniform_int_distribution class 
    uniform_int_distribution<int> 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



相关用法


注:本文由纯净天空筛选整理自srinam大神的英文原创作品 std::uniform_int_distribution reset() method in C++ with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。