public member function
<random>
std::linear_congruential_engine::(constructor) (1)explicit linear_congruential_engine ( result_type val = default_seed );(2)
template <class Sseq>explicit linear_congruential_engine ( Sseq& q );
Construct linear congruential engine
Constructs a linear_congruential_engine object, and initializes its internal state value:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// linear_congruential_engine constructor
#include <iostream>
#include <chrono>
#include <random>
int main ()
{
// obtain a seed from the system clock:
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
// obtain a seed from the user:
std::string str;
std::cout << "Please, enter a seed: ";
std::getline(std::cin,str);
std::seed_seq seed2 (str.begin(),str.end());
std::minstd_rand0 g1 (seed1); // minstd_rand0 is a standard linear_congruential_engine
std::cout << "A time seed produced: " << g1() << std::endl;
std::minstd_rand0 g2 (seed2);
std::cout << "Your seed produced: " << g2() << std::endl;
return 0;
}
Please, enter a seed: Park-Miller A time seed produced: 1227992885 Your seed produced: 1296106123
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4