Ово заглавље уводи могућности генерисања случајних бројева. Ова библиотека омогућава производњу случајних бројева користећи комбинације генератора и дистрибуција.
- Дистрибуције : Објекти који трансформишу низове бројева које генерише генератор у низове бројева који прате специфичну дистрибуцију случајних променљивих као што је униформна нормална или биномна.
Генератори
И. Псеудо-случајни бројеви мотора: Они користе алгоритам за генерисање случајних бројева на основу почетног семена. ово су:

1. линеарни_конгруенцијални_мотор : То је најједноставнији механизам у СТЛ библиотеци који генерише насумичне неозначене целе бројеве. Следи:
обрнути низ у Јави
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. мерсенне_твистер_енгине: То је механизам случајних бројева заснован на алгоритму Мерсенне Твистер. Он производи насумичне бројеве без предзнака високог квалитета у интервалу [0 (2^в)-1].
где је 'в' величина речи: број битова сваке речи у секвенци стања.
// 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. субтрацт_витх_царри_енгине: То је генератор псеудо-случајних бројева који производи неозначене целе бројеве.
Алгоритам који се користи је лаггед фибоначијев генератор са секвенцом стања од р целобројних елемената плус једна носећа вредност.
// 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
ИИ. Генератор случајних бројева : То је генератор случајних бројева који производи недетерминистичке случајне бројеве.
// 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
ИИИ. Механизми псеудо-случајних бројева (инстанције) : Ово су конкретне инстанције мотора генератора и адаптера:
доба дармендра

1. дефаулт_рандом_енгине : Ово је класа мотора случајних бројева која генерише псеудо-случајне бројеве.
Функција мења унутрашње стање за оно што мења вредност стања према датом алгоритму:
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. минстд_ранд: Генерише псеудо случајне бројеве; слично је са линеарни конгруентни генератор
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.МТ19937: То је генератор Мерсенне Твистер 19937. То је псеудо-случајни генератор 32-битних бројева са величином стања од 19937 бита.
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. ранлук24_басе: То је Ранлук 24 основни генератор. То је псеудо-случајни генератор 24-битних бројева који се обично користи као основни механизам за ранлук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
Сличан формат је применљив и за остале примере.
ИВ. Мотор Адаптерс

1. дисцард_блоцк_енгине: То је шаблон класе адаптера мотора који прилагођава а Мотор генератора псеудослучајних бројева укуцајте користећи само 'р' елементе сваког блока 'п' елемената из секвенце коју производи одбацујући остатак.
Адаптер чува интерно бројање колико је елемената произведено у тренутном блоку.
Стандардни генератори ранлук24 и ранлук48 прилагодити а субтрацт_витх_царри_енгине користећи овај адаптер.
// 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. независни_битови_енгине: То је шаблон класе адаптера мотора који прилагођава а Мотор генератора псеудослучајних бројева тип за производњу случајних бројева са одређеним бројем битова (в).
Алгоритам транзиције машине позива оператор() члана основног механизма онолико пута колико је потребно да добије довољно значајних битова за конструисање случајне вредности.
// 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. схуффле_ордер_енгине: То је шаблон класе адаптера мотора који прилагођава а Мотор генератора псеудослучајних бројева откуцајте тако да се бројеви испоручују различитим редоследом.
Објекат интерно чува бафер од к генерисаних бројева и када се то затражи враћа насумично одабрани број унутар бафера замењујући га вредношћу добијеном од његовог основног механизма.
Алгоритам транзиције механизма бира вредност у интерној табели (коју враћа функција) и замењује је новом вредношћу добијеном из његовог основног механизма.
// 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Креирај квиз