Skip to content
Related Articles

Related Articles

std::uniform_int_distribution reset() method in C++ with examples
  • Last Updated : 17 Jun, 2019

The reset() method of uniform_int_distribution class in C++ is used to reset this uniform_int_distribution.

Syntax:

void reset();

Parameters: This method do not accepts any parameters.

Return Value: This method do not return anything.

Example:




// 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;
}
Output:
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

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

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :