이 헤더는 난수 생성 기능을 소개합니다. 이 라이브러리를 사용하면 생성기와 분포의 조합을 사용하여 난수를 생성할 수 있습니다.
- 배포판 : 생성기에 의해 생성된 숫자 시퀀스를 균일 정규 또는 이항과 같은 특정 확률 변수 분포를 따르는 숫자 시퀀스로 변환하는 개체입니다.
발전기
I. 의사 난수 엔진: 그들은 알고리즘을 사용하여 초기 시드를 기반으로 난수를 생성합니다. 이것들은 다음과 같습니다:

1. 선형_합치_엔진 : 부호 없는 임의의 정수를 생성하는 STL 라이브러리의 가장 간단한 엔진입니다. 다음과 같습니다:
Java에 있는 동안 수행
x = (a.x +c) mod m Where x= current state value a = multiplier parameter ; if m is not zero this parameter should be lower than m. c = increment parameter ; if m is not zero this parameter should be lower than m. m = modulus parameter
// C++ program to illustrate // the use of operator() max and min // in linear_congruential_engine #include #include #include using namespace std; // driver program int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // minstd_rand0 is a standard // linear_congruential_engine minstd_rand0 generator (seed); // generates the random number cout << generator() << ' is a random number between '; //use of min and max functions cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
211182246 is a random number between 1 and 2147483646
2. 메르센_트위스터_엔진: Mersenne Twister 알고리즘을 기반으로 한 난수 엔진입니다. 간격 [0 (2^w)-1]에서 고품질의 부호 없는 정수 난수를 생성합니다.
여기서 'w'는 단어 크기입니다. 상태 시퀀스에 있는 각 단어의 비트 수입니다.
// C++ program to illustrate the use of // operator() min and max // in mersenne_twister_engine #include #include #include using namespace std; // Driver program int main () { // finds the time between the system clock // (present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // mt19937 is a standard mersenne_twister_engine mt19937 generator (seed); // use of operator() cout << generator() << ' is a random number between '; // use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
3348201622 is a random number between 0 and 4294967295
3. subtract_with_carry_engine: 부호 없는 정수를 생성하는 의사 난수 생성기 엔진입니다.
사용된 알고리즘은 지연된 알고리즘입니다. 피보나치 생성기 r개의 정수 요소와 하나의 캐리 값으로 구성된 상태 시퀀스를 사용합니다.
// C++ program to illustrate the use of // operator() min and max // in subtract_with_carry_engine #include #include #include using namespace std; // Driver program int main () { // finds the time between the system clock // (present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); subtract_with_carry_engine<unsigned 24 10 24> generator (seed); // use of operator() cout << generator() << ' is a random number between '; // use of min and max cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
8606455 is a random number between 0 and 16777215
II. 난수 생성기 : 비결정적 난수를 생성하는 난수 생성기입니다.
// C++ program to illustrate the use of // operator() min and max // in random_device #include #include using namespace std; //Driver program int main () { random_device example; cout << 'default random_device characteristics:' << endl; // use of min cout << 'minimum: ' << example.min() << endl; // use of max cout << 'maximum: ' << example.max() << endl; // use of entropy cout << 'entropy: ' << example.entropy() << endl; // use of operator() cout << 'a random number: ' << example() << endl; return 0; }
산출:
default random_device characteristics: minimum: 0 maximum: 4294967295 entropy: 0 a random number: 3705944883
III. 의사 난수 엔진(인스턴스화) : 발전기 엔진 및 어댑터의 특정 인스턴스화는 다음과 같습니다.
vlc는 YouTube에서 비디오를 다운로드합니다.

1. default_random_engine : 의사 난수를 생성하는 난수 엔진 클래스입니다.
이 함수는 주어진 알고리즘에 따라 상태 값을 수정하는 방식으로 내부 상태를 변경합니다.
x= (a.x + c)mod m Where x= current state value a and c = respective class template parameters m = class template parameterC++
// C++ program to illustrate the use of // operator() min and max // in default_random_engine #include #include #include using namespace std; // Driver program int main () { // finds the time between the system clock // (present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // minstd_rand0 is a standard linear_congruential_engine minstd_rand0 generator (seed); // generates the random number cout << generator() << ' is a random number between '; // Use of min and max cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
201066682 is a random number between 1 and 2147483646
2. minstd_rand: 의사 난수를 생성합니다. 그것은 비슷하다 선형 합동 생성기
x = (a.x + c) mod m where x= current state value a c and m=class template parameter
// C++ program to illustrate // the use of operator() max and min // in minstd_rand #include #include #include using namespace std; //Driver program int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // minstd_rand0 is a standard //linear_congruential_engine minstd_rand0 generator (seed); // use of operator() cout << generator() << ' is a random number between '; //use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
489592737 is a random number between 1 and 2147483646
3.MT19937: Mersenne Twister 19937 생성기입니다. 상태 크기가 19937비트인 32비트 숫자의 의사 난수 생성기입니다.
C++
// C++ program to illustrate the // use of operator()min and max // in mt19937 #include #include #include using namespace std; // Driver program int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // mt19937 is a standard //mersenne_twister_engine mt19937 generator (seed); //use of operator() cout << generator() << ' is a random number between '; //use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
1445431990 is a random number between 0 and 4294967295
4. ranlux24_base: Ranlux 24 베이스 생성기 입니다. 일반적으로 ranlux24 생성기의 기본 엔진으로 사용되는 24비트 숫자의 뺄셈 의사 난수 생성기입니다.
이 함수는 요소에 캐리 포함 빼기 연산을 적용하는 전환 알고리즘을 호출하여 내부 상태를 변경합니다.
// C++ program to illustrate // the use of operator()min and max // in ranlux24_base #include #include #include using namespace std; //Driver program int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); subtract_with_carry_engine<unsigned241024> generator (seed); //use of operator() cout << generator() << ' is a random number between '; //use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
자바 문자를 문자열로
7275352 is a random number between 0 and 16777215
다른 예에도 비슷한 형식이 적용됩니다.
IV. 엔진 어댑터

1. 폐기_블록_엔진: 이는 다음을 적용하는 엔진 어댑터 클래스 템플릿입니다. 의사 난수 생성기 엔진 나머지는 버리고 생성된 시퀀스에서 'p' 요소의 각 블록에서 'r' 요소만 사용하여 유형을 지정합니다.
어댑터는 현재 블록에서 생성된 요소 수에 대한 내부 개수를 유지합니다.
jdbc
표준 발전기 란룩스24 그리고 란룩스48 적응하다 subtract_with_carry_engine 이 어댑터를 사용하여.
// C++ program to illustrate // the use of operator()min and max // in the discard_block_engine #include #include #include using namespace std; //Driver program int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // ranlux24 is a standard instantiation //of discard_block_engine: ranlux24 generator (seed); //use of operator() cout << generator() << ' is a random number between '; //use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
8132325 is a random number between 0 and 16777215
2. independent_bits_engine: 이는 다음을 적용하는 엔진 어댑터 클래스 템플릿입니다. 의사 난수 생성기 엔진 특정 수의 비트(w)를 사용하여 난수를 생성하는 유형입니다.
엔진의 전환 알고리즘은 임의의 값을 구성하기에 충분한 유효 비트를 얻기 위해 필요한 만큼 기본 엔진의 Operator() 멤버를 호출합니다.
// C++ program to illustrate // the use of operator()min and max // in independent_bits_engine #include #include // It imports the symbol names in // std namespace and possibly in Global namespace. #include #include using namespace std; //Driver program int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); //use of independent_bits_engine independent_bits_engine<mt1993764uint_fast64_t> generator (seed); //use of operator() cout << generator() << ' is a random number between '; //use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
13551674127875514537 is a random number between 0 and 184467
3. shuffle_order_engine: 이는 다음을 적용하는 엔진 어댑터 클래스 템플릿입니다. 의사 난수 생성기 엔진 숫자가 다른 순서로 전달되도록 입력하세요.
객체는 내부적으로 생성된 k개의 숫자로 구성된 버퍼를 유지하며 요청 시 버퍼 내에서 무작위로 선택된 숫자를 반환하며 이를 기본 엔진에서 얻은 값으로 대체합니다.
엔진의 전환 알고리즘은 내부 테이블(함수에 의해 반환됨)에서 값을 선택하고 이를 기본 엔진에서 얻은 새 값으로 바꿉니다.
// C++ program to illustrate // the use of operator()min and max // in shuffle_order_engine #include #include #include using namespace std; int main () { // finds the time between the system clock //(present time) and clock's epoch unsigned seed = chrono::system_clock::now().time_since_epoch().count(); // ranlux24 is a standard instantiation // of discard_block_engine: ranlux24 generator (seed); //use of operator() cout << generator() << ' is a random number between '; //use of max and min cout << generator.min() << ' and ' << generator.max(); return 0; }
산출:
9213395 is a random number between 0 and 16777215퀴즈 만들기