Bu başlık rastgele sayı üretme olanaklarını tanıtmaktadır. Bu kütüphane, oluşturucu ve dağıtım kombinasyonlarını kullanarak rastgele sayılar üretmeye olanak tanır.
- Dağılımlar : Bir oluşturucu tarafından oluşturulan sayı dizilerini, tekdüze Normal veya Binom gibi belirli bir rastgele değişken dağılımını izleyen sayı dizilerine dönüştüren nesneler.
Jeneratörler
I. Sözde rastgele sayı motorları: Başlangıçtaki bir tohuma dayalı olarak rastgele sayılar üretmek için bir algoritma kullanıyorlar. Bunlar:

1. doğrusal_uyumlu_motor : STL kütüphanesindeki rastgele işaretsiz tamsayılar üreten en basit motordur. Şöyle:
engellenen numaralar
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; }
Çıkış:
211182246 is a random number between 1 and 2147483646
2. mersenne_twister_engine: Mersenne Twister algoritmasına dayalı bir rastgele sayı motorudur. [0 (2^w)-1] aralığında yüksek kalitede işaretsiz tamsayı rastgele sayılar üretir.
burada 'w' kelime boyutudur: Durum dizisindeki her kelimenin bit sayısı.
// 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; }
Çıkış:
3348201622 is a random number between 0 and 4294967295
3. subtract_with_carry_engine: İşaretsiz tamsayılar üreten bir sözde rastgele sayı üreteci motorudur.
Kullanılan algoritma gecikmeli fibonacci üreteci r tamsayı elemanları artı bir taşıma değeri içeren bir durum dizisi ile.
// 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; }
Çıkış:
8606455 is a random number between 0 and 16777215
II. Rastgele sayı üreteci : Deterministik olmayan rastgele sayılar üreten bir rastgele sayı üretecidir.
karakter java
// 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; }
Çıkış:
default random_device characteristics: minimum: 0 maximum: 4294967295 entropy: 0 a random number: 3705944883
III. Sözde rastgele sayı motorları (örneklemeler) : Bunlar jeneratör motorlarının ve adaptörlerinin özel örnekleridir:

1. default_random_engine : Bu, sözde rastgele sayılar üreten bir rastgele sayı motoru sınıfıdır.
İşlev, dahili durumu, verilen algoritmaya göre durum değerini değiştiren bir değişiklikle değiştirir:
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; }
Çıkış:
201066682 is a random number between 1 and 2147483646
2. minstd_rand: Sahte rastgele sayılar üretir; buna benzer doğrusal uyumlu üreteç
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; }
Çıkış:
489592737 is a random number between 1 and 2147483646
3.MT19937: Mersenne Twister 19937 jeneratörüdür. Durum boyutu 19937 bit olan 32 bitlik sayılardan oluşan sözde rastgele bir jeneratördür.
Eclipse'de javafx
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; }
Çıkış:
1445431990 is a random number between 0 and 4294967295
4. ranlux24_base: Ranlux 24 baz jeneratörüdür. Bu, genellikle ranlux24 oluşturucusu için temel motor olarak kullanılan, 24 bitlik sayılardan oluşan, taşıma ile çıkarmalı sözde rastgele oluşturucudur.
İşlev, öğeye taşıma ile çıkarma işlemi uygulayan geçiş algoritmasını çağırarak iç durumu değiştirir.
// 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; }
Çıkış:
7275352 is a random number between 0 and 16777215
Diğer örnekler için de benzer format geçerlidir.
IV. Motor Adaptörleri

1. throw_block_engine: uyarlayan bir motor adaptör sınıfı şablonudur. sözde rastgele sayı üreteci Motor geri kalanını atarak ürettiği dizideki 'p' öğelerinin her bloğunun yalnızca 'r' öğelerini kullanarak yazın.
Bağdaştırıcı, geçerli blokta kaç öğenin üretildiğine dair dahili bir sayım tutar.
Standart jeneratörler ranlux24 Ve ranlux48 uyarlamak subtract_with_carry_engine bu adaptörü kullanarak.
// 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; }
Çıkış:
gb kaç mb
8132325 is a random number between 0 and 16777215
2. bağımsız_bits_engine: uyarlayan bir motor adaptör sınıfı şablonudur. sözde rastgele sayı üreteci Motor Belirli sayıda bit (w) ile rastgele sayılar üretmek için yazın.
Motorun geçiş algoritması, rastgele bir değer oluşturmaya yetecek kadar önemli bit elde etmek için temel motorların operatör() üyesini gerektiği kadar çağırır.
// 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; }
Çıkış:
13551674127875514537 is a random number between 0 and 184467
3. shuffle_order_engine: uyarlayan bir motor adaptör sınıfı şablonudur. sözde rastgele sayı üreteci Motor sayıların farklı bir sırayla iletilmesini sağlayacak şekilde yazın.
Nesne, dahili olarak üretilen k sayıdan oluşan bir arabellek tutar ve istendiğinde, arabellek içinde rastgele seçilen bir sayıyı, temel motorundan elde edilen bir değerle değiştirerek döndürür.
Motorun geçiş algoritması, dahili tablodan (işlev tarafından döndürülen) bir değer seçer ve onu temel motorundan elde edilen yeni bir değerle değiştirir.
// 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; }
Çıkış:
9213395 is a random number between 0 and 16777215Test Oluştur