Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

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

  • Last Updated : 17 Jun, 2019
Geek Week

The b() method of uniform_int_distribution class in C++ is used to get the upper bound of this uniform_int_distribution. If there is no upper bound then this method returns std::numeric_limits::max().

Syntax:

result_type b() const;

Parameters: This method do not accepts any parameters.

Return Value: This method return the ‘b’ parameter in the distribution, which is the upper bound or the maximum possibly generated value in this uniform_int_distribution. Its default value is std::numeric_limits::max().

Example:




// C++ code to demonstrate
// the working of b() 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 b()
    cout << "Upper Bound: "
         << distribution.b() << endl;
  
    return 0;
}
Output:
Upper Bound: 100

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

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 :