當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。