Šī galvene ievieš nejaušu skaitļu ģenerēšanas iespējas. Šī bibliotēka ļauj iegūt nejaušus skaitļus, izmantojot ģeneratoru un sadalījumu kombinācijas.
- Izplatījumi : objekti, kas pārveido ģeneratora ģenerētās skaitļu virknes skaitļu secībās, kas atbilst noteiktam nejaušā mainīgā sadalījumam, piemēram, vienmērīgam normālam vai binomiālam.
Ģeneratori
I. Pseidogadījuma skaitļu dzinēji: Viņi izmanto algoritmu, lai ģenerētu nejaušus skaitļus, pamatojoties uz sākotnējo sēklu. Tie ir:

1. lineārais_kongruenciālais_dzinējs : tas ir vienkāršākais dzinējs STL bibliotēkā, kas ģenerē nejaušus neparakstītus veselus skaitļus. No tā izriet:
java masīva šķēle
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; }
Izvade:
211182246 is a random number between 1 and 2147483646
2. mersenne_twister_engine: Tas ir nejaušu skaitļu dzinējs, kura pamatā ir Mersenne Twister algoritms. Tas rada augstas kvalitātes neparakstītus veselus nejaušus skaitļus intervālā [0 (2^w)-1].
kur “w” ir vārda lielums: katra vārda bitu skaits stāvokļa secībā.
// 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; }
Izvade:
3348201622 is a random number between 0 and 4294967295
3. subtract_with_carry_engine: Tas ir pseidogadījuma skaitļu ģenerators, kas rada neparakstītus veselus skaitļus.
Izmantotais algoritms ir aizkavējies Fibonači ģenerators ar stāvokļu secību r veselu skaitļu elementu plus viena pārneses vērtība.
// 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; }
Izvade:
8606455 is a random number between 0 and 16777215
II. Nejaušo skaitļu ģenerators : tas ir nejaušu skaitļu ģenerators, kas rada nedeterminētus nejaušus skaitļus.
// 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; }
Izvade:
default random_device characteristics: minimum: 0 maximum: 4294967295 entropy: 0 a random number: 3705944883
III. Pseidogadījuma skaitļu dzinēji (instantiācijas) : Šīs ir ģeneratoru dzinēju un adapteru īpašās instancijas:

1. noklusējuma_gadījuma_dzinējs : šī ir nejaušu skaitļu dzinēju klase, kas ģenerē pseidogadījuma skaitļus.
cast virkni int java
Funkcija maina iekšējo stāvokli par vienu, kas maina stāvokļa vērtību saskaņā ar doto algoritmu:
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; }
Izvade:
201066682 is a random number between 1 and 2147483646
2. minstd_rand: Tas ģenerē pseido nejaušus skaitļus; tas ir līdzīgs lineārais kongruenciālais ģenerators
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; }
Izvade:
489592737 is a random number between 1 and 2147483646
3.MT19937: Tas ir Mersenne Twister 19937 ģenerators. Tas ir 32 bitu skaitļu pseidogadījuma ģenerators ar stāvokļa lielumu 19937 biti.
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; }
Izvade:
1445431990 is a random number between 0 and 4294967295
4. ranlux24_base: Tas ir Ranlux 24 bāzes ģenerators. Tas ir 24 bitu skaitļu pseidogadījuma ģenerators ar atņemšanu ar pārnesi, ko parasti izmanto kā ranlux24 ģeneratora bāzes dzinēju.
cilpa bash
Funkcija maina iekšējo stāvokli, izsaucot savu pārejas algoritmu, kas elementam piemēro atņemšanas ar pārnešanas darbību.
// 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; }
Izvade:
7275352 is a random number between 0 and 16777215
Līdzīgs formāts ir piemērojams arī citiem piemēriem.
IV. Dzinēja adapteri

1. discard_block_engine: Tā ir dzinēja adaptera klases veidne, kas pielāgo a pseidogadījuma skaitļu ģenerators Dzinējs ierakstiet, izmantojot tikai “r” elementus katrā “p” elementu blokā no secības, ko tas rada, pārējos izmetot.
Adapteris saglabā iekšējo uzskaiti, cik daudz elementu ir saražoti pašreizējā blokā.
Standarta ģeneratori ranlux24 un ranlux48 pielāgot a atņemt_ar_carry_engine izmantojot šo adapteri.
// 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; }
Izvade:
8132325 is a random number between 0 and 16777215
2. independent_bits_engine: Tā ir dzinēja adaptera klases veidne, kas pielāgo a pseidogadījuma skaitļu ģenerators Dzinējs tipa, lai iegūtu nejaušus skaitļus ar noteiktu bitu skaitu (w).
Dzinēja pārejas algoritms izsauc bāzes dzinēju operatora() locekli tik reižu, cik nepieciešams, lai iegūtu pietiekami daudz nozīmīgu bitu, lai izveidotu nejaušu vērtību.
// 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; }
Izvade:
13551674127875514537 is a random number between 0 and 184467
3. shuffle_order_engine: Tā ir dzinēja adaptera klases veidne, kas pielāgo a pseidogadījuma skaitļu ģenerators Dzinējs ierakstiet, lai numuri tiktu piegādāti citā secībā.
Objekts iekšēji saglabā k ģenerētu skaitļu buferi un pēc pieprasījuma atgriež buferī nejauši izvēlētu skaitli, aizstājot to ar vērtību, kas iegūta no tā bāzes dzinēja.
Dzinēja pārejas algoritms izvēlas vērtību iekšējā tabulā (kuru atgriež funkcija) un aizstāj to ar jaunu vērtību, kas iegūta no tā bāzes dzinēja.
// 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; }
Izvade:
ms Word ātrās piekļuves rīkjosla
9213395 is a random number between 0 and 16777215Izveidojiet viktorīnu