Overview
This is a random number distribution class that generates sequences of pseudo-random numbers from pseudo-random number engines.
Details
Syntax
//IntType:A integer type. template <class IntType = int> class uniform_int_distribution;
member types
Following properties are defined.
Name | Definition |
---|---|
uint_least32_t result_type | The type of the numbers generated. |
param_type | The type returned by param method. |
Constructor
Name | Description |
---|---|
| Constructs a uniform_int_distribution object, and initializes its internal state value: Example
//1 uniform_int_distribution<long> di(1,100); uniform_int_distribution<> di2(1,100); //2 uniform_int_distribution<long> di3(di.param()); uniform_int_distribution<> di4(di2.param()); |
Methods
Name | Description |
---|---|
result_type min() | Returns the lower bound of the returned value. i.e., a Example uniform_int_distribution<int> di(1,100); //prints 1 cout << di.min() << endl; |
result_type max() | Returns the upper bound of the returned value. i.e., b Example uniform_int_distribution<int> di(1,100); //prints 100 cout << di.max() << endl; |
|
uniform_int_distribution<int> di(1,100); //1 auto p = di.param(); //2 uniform_int_distribution<int> di2; di2.param(p); |
| Generates random numbers that are distributed according to the associated probability function. The entropy is acquired by calling g.operator().
Example default_random_engine g(20160921); //1 uniform_int_distribution<int> di(1,100); //prints 79 cout << di(g) << endl; //2 uniform_int_distribution<int> di2; //prints 96 cout << di2(g,di.param()) << endl; |
void reset() | Resets the distribution, so that subsequent uses of the object do not depend on values already produced by it. |
result_type a() | Returns lower bound of the distribution parameter. Example uniform_int_distribution<int> di(1,100); //prints 1 cout << di.a() << endl; |
result_type b() | Returns upper bound of the distribution parameter. Example uniform_int_distribution<int> di(1,100); //prints 100 cout << di.b() << endl; |
External Methods
Name | Description |
---|---|
ostream& operator<< (ostream& os, const uniform_int_distribution& di ) | Saves internal state of di to os. Example uniform_int_distribution<int> di(1,100); stringstream ss; ss << di; |
istream& operator>> (istream& is, uniform_int_distribution& di ) | Restores internal state of di from is. Example uniform_int_distribution<int> di(1,100);stringstream ss; ss << di; |
bool operator== (const uniform_int_distribution& di, const uniform_int_distribution& di2) | Returns true if di and di2 are the same. |
bool operator!= (const uniform_int_distribution& di, const uniform_int_distribution& di2) | Returns true if di and di2 are not the same. |
No comments:
Post a Comment