Overview
This is a random number engine class that generates pseudo-random numbers.
Details
Its implementation is platform specific. Here it's assumed that linear_congruential_engine is used.
member types
Following properties are defined.
Name | Definition |
---|---|
uint_least32_t result_type | The type of the numbers generated |
Constructor
Name | Description |
---|---|
| Constructs a linear_congruential_engine object, and initializes its internal state value: Example
//1 default_random_engine d(21092018u); //2 string s = "Khrisha Rao"; seed_seq seed (s.begin(),s.end()); default_random_engine d2(seed); |
Methods
Name | Description |
---|---|
result_type default_random_engine ::min() | Returns the minimum value potentially generated by the random-number engine. Example default_random_engine(); //prints 1 cout << default_random_engine::min() << endl; |
result_type default_random_engine ::max() | Returns the maximum value potentially generated by the random-number engine. Example default_random_engine(); //prints 2147483646 cout << default_random_engine::max() << endl; |
| Reinitializes its internal state value: Example
//1 default_random_engine d; d.seed(21092018u); //2 string s = "Khrisha Rao"; seed_seq seed (s.begin(),s.end()); d.seed(seed); |
result_type operator()() | Returns a new random number. The function advances the internal state by one, which modifies the state value. Example default_random_engine d;
//prints 16807
cout << d() << endl; |
void discard (unsigned long long z) | Advances the internal state by z notches, as if operator() was called z times, but without generating any numbers in the process. The effects on the state sequence are the same as if the transition algorithm was applied as many times as notches advanced. Example default_random_engine d; d.discard(300); //prints 1495170053 cout << d() << endl; |
External Methods
Name | Description |
---|---|
ostream& operator<< (ostream& os, const default_random_engine& d ) | Saves internal state of d to os. Example default_random_engine d(400); stringstream ss; ss << d << endl; //prints 400 cout << d << endl; |
istream& operator>> (istream& is, default_random_engine& d ) | Restores internal state of d from is. Example default_random_engine d(400); stringstream ss; ss << d << endl; //prints 400 cout << d << endl; //prints 400 ss >> d; cout << d << endl; |
bool operator== (const default_random_engine& d, const default_random_engine& d2) | Returns true if d and d2 are the same. |
bool operator!= (const default_random_engine& d, const default_random_engine& d2) | Returns true if d and d2 are not the same. |
No comments:
Post a Comment