Ez a fejléc véletlenszám-generálási lehetőségeket mutat be. Ez a könyvtár lehetővé teszi véletlen számok előállítását generátorok és eloszlások kombinációi segítségével.
- Elosztások : Olyan objektumok, amelyek generátor által generált számsorozatokat olyan számsorozatokká alakítanak át, amelyek meghatározott valószínűségi változó-eloszlást követnek, például egységes normál vagy binomiális.
Generátorok
I. Ál-véletlenszámú motorok: Algoritmust használnak véletlen számok generálására egy kezdeti mag alapján. Ezek a következők:

1. lineáris_kongruenciális_motor : Az STL könyvtár legegyszerűbb motorja, amely véletlenszerű előjel nélküli egész számokat generál. Ebből következik:
hány millió van egy milliárdban
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; }
Kimenet:
211182246 is a random number between 1 and 2147483646
2. mersenne_twister_engine: Ez egy véletlenszámú motor, amely Mersenne Twister algoritmuson alapul. Kiváló minőségű előjel nélküli egész véletlenszerű számokat állít elő a [0 (2^w)-1] intervallumban.
ahol "w" a szó mérete: Az állapotsorozat egyes szavainak bitjeinek száma.
// 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; }
Kimenet:
3348201622 is a random number between 0 and 4294967295
3. subtract_with_carry_engine: Ez egy pszeudo-véletlen számgenerátor, amely előjel nélküli egész számokat állít elő.
A használt algoritmus egy késleltetett fibonacci generátor r egész elemből és egy hordozó értékből álló állapotsorral.
// 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; }
Kimenet:
8606455 is a random number between 0 and 16777215
II. Véletlenszám-generátor : Ez egy véletlenszám-generátor, amely nem determinisztikus véletlen számokat állít elő.
// 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; }
Kimenet:
default random_device characteristics: minimum: 0 maximum: 4294967295 entropy: 0 a random number: 3705944883
III. Pszeudo-véletlenszámú motorok (példányosítások) : Ezek a generátormotorok és adapterek egyedi példányai:
knn

1. alapértelmezett_random_motor : Ez egy véletlenszámú motorosztály, amely pszeudo-véletlen számokat generál.
A függvény a belső állapotot eggyel módosítja, ami az adott algoritmusnak megfelelően módosítja az állapotértéket:
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; }
Kimenet:
201066682 is a random number between 1 and 2147483646
2. minstd_rand: Pszeudo véletlen számokat generál; ehhez hasonló lineáris kongruenciális generátor
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; }
Kimenet:
ha mást ha java
489592737 is a random number between 1 and 2147483646
3.MT19937: Ez a Mersenne Twister 19937 generátor. Ez egy pszeudo-véletlenszerű generátor 32 bites számokból, állapotmérete 19937 bit.
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; }
Kimenet:
1445431990 is a random number between 0 and 4294967295
4. ranlux24_base: Ez egy Ranlux 24 alapgenerátor. Ez egy 24 bites számok kivonás és átvitel pszeudovéletlen generátora, amelyet általában a ranlux24 generátor alapmotorjaként használnak.
A függvény megváltoztatja a belső állapotot azáltal, hogy meghívja az átmenet algoritmusát, amely egy kivonás-viszi műveletet alkalmaz az elemen.
// 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; }
Kimenet:
7275352 is a random number between 0 and 16777215
Hasonló formátum alkalmazható a többi példában is.
IV. Motor adapterek

1. discard_block_engine: Ez egy motoradapter osztálysablon, amely alkalmazkodik a pszeudo-véletlenszám-generátor Motor írja be, csak az „r” elemet használva minden egyes „p” elem blokkjából az általa létrehozott sorozatból, a többit eldobva.
Az adapter belső számlálást tart arról, hogy hány elemet állítottak elő az aktuális blokkban.
A szabványos generátorok ranlux24 és ranlux48 alkalmazkodni a vonja ki_carry_engine-nel ennek az adapternek a használatával.
// 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; }
Kimenet:
8132325 is a random number between 0 and 16777215
2. független_bitek_motor: Ez egy motoradapter osztálysablon, amely alkalmazkodik a pszeudo-véletlenszám-generátor Motor írja be, hogy véletlen számokat állítson elő meghatározott számú bittel (w).
A motor átmeneti algoritmusa annyiszor hívja meg az alapmotorok operator() tagját, ahányszor szükséges, hogy elegendő jelentős bitet kapjon egy véletlenszerű érték létrehozásához.
// 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; }
Kimenet:
bellford algoritmus
13551674127875514537 is a random number between 0 and 184467
3. shuffle_order_engine: Ez egy motoradapter osztálysablon, amely alkalmazkodik a pszeudo-véletlenszám-generátor Motor írja be, hogy a számok eltérő sorrendben jelenjenek meg.
Az objektum egy k generált számból álló puffert tart belsőleg, és kérésre egy véletlenszerűen kiválasztott számot ad vissza a pufferen belül, lecserélve azt az alapmotortól kapott értékre.
A motor átmeneti algoritmusa kiválaszt egy értéket a belső táblából (amelyet a függvény visszaad), és lecseréli az alapmotorból kapott új értékre.
// 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; }
Kimenet:
9213395 is a random number between 0 and 16777215Kvíz létrehozása