std::uniform_int_distribution reset() method in C++ with examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.