يقدم هذا الرأس مرافق توليد أرقام عشوائية. تسمح هذه المكتبة بإنتاج أرقام عشوائية باستخدام مجموعات من المولدات والتوزيعات.
- توزيعات : الكائنات التي تحول تسلسلات الأرقام التي تم إنشاؤها بواسطة المولد إلى تسلسلات من الأرقام التي تتبع توزيع متغير عشوائي محدد مثل عادي أو ثنائي الحد.
مولدات
I. محركات الأرقام العشوائية الزائفة: يستخدمون خوارزمية لإنشاء أرقام عشوائية بناءً على بذرة أولية. هذه هي:

1. محرك متطابق خطي : إنه أبسط محرك في مكتبة STL يقوم بإنشاء أرقام صحيحة عشوائية غير موقعة. يلي:
سلسلة إلى كائن json
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: إنه محرك أرقام عشوائي يعتمد على خوارزمية 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. محرك الطرح مع_الحمل: إنه محرك مولد أرقام عشوائية زائفة ينتج أرقامًا صحيحة غير موقعة.
الخوارزمية المستخدمة متخلفة مولد فيبوناتشي مع تسلسل حالة من العناصر الصحيحة 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
ثانيا. مولد رقم عشوائي : هو مولد أرقام عشوائية ينتج أرقام عشوائية غير حتمية.
بروتوكول UDP
// 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. 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. مينستد_راند: يقوم بإنشاء أرقام عشوائية زائفة؛ إنه مشابه لـ مولد التطابق الخطي
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. إنه مولد عشوائي زائف لأرقام 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.ranlux24_base: إنه مولد أساسي Ranlux 24. إنه مولد عشوائي زائف للطرح مع الحمل لأرقام 24 بت يستخدم بشكل عام كمحرك أساسي لمولد ranlux24.
تقوم الدالة بتغيير الحالة الداخلية عن طريق استدعاء خوارزمية الانتقال الخاصة بها والتي تطبق عملية الطرح مع الحمل على العنصر.
// 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.discover_block_engine: إنه قالب فئة محول المحرك الذي يتكيف مع محرك مولد الأرقام العشوائية الزائفة اكتب باستخدام عناصر "r" فقط من كل كتلة من عناصر "p" من التسلسل الذي ينتجه مع تجاهل الباقي.
يحتفظ المحول بعدد داخلي لعدد العناصر التي تم إنتاجها في الكتلة الحالية.
المولدات القياسية ranlux24 و رانلوكس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. محرك البتات المستقل: إنه قالب فئة محول المحرك الذي يتكيف مع محرك مولد الأرقام العشوائية الزائفة اكتب لإنتاج أرقام عشوائية بعدد محدد من البتات (w).
تستدعي خوارزمية انتقال المحرك عضو المشغل () الخاص بالمحركات الأساسية عدة مرات حسب الحاجة للحصول على ما يكفي من البتات المهمة لإنشاء قيمة عشوائية.
// 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. محرك النظام العشوائي: إنه قالب فئة محول المحرك الذي يتكيف مع محرك مولد الأرقام العشوائية الزائفة اكتب بحيث يتم تسليم الأرقام في تسلسل مختلف.
يحتفظ الكائن بمخزن مؤقت للأرقام التي تم إنشاؤها بواسطة 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إنشاء اختبار