Related Articles

Related Articles

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

The max() method of uniform_int_distribution class in C++ is used to get the maximum possible value that can be generated by this uniform_int_distribution.

Syntax:

result_type max() const;

Parameters: This method do not accepts any parameters.

Return Value: This method return the maximum possibly generated value in this uniform_int_distribution.

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ code to demonstrate
// the working of max() function
  
#include <iostream>
  
// for uniform_int_distribution function
#include <random>
  
using namespace std;
  
int main()
{
    int a = 10, b = 100;
  
    // Initializing of uniform_int_distribution class
    uniform_int_distribution<int> distribution(a, b);
  
    // Using max()
    cout << "Max value that can be generated"
         << " by this uniform_int_distribution: "
         << distribution.max() << endl;
  
    return 0;
}

chevron_right


Output:

Max value that can be generated by this uniform_int_distribution: 100

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

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :