std::linear_congruential_engine
來自 cppreference.com
定義於標頭檔案 <random> |
||
template< class UIntType, |
(C++11 起) | |
linear_congruential_engine
是一個基於線性同餘生成器(LCG)的隨機數引擎。
目錄 |
[編輯] 模板引數
UIntType | - | 生成器生成的返回型別。如果它不是 unsigned short、unsigned int、unsigned long 或 unsigned long long 之一,則效果未定義。 |
a | - | 乘數項 |
c | - | 增量項 |
m | - | 模數項 |
當 m 不為零時,如果 a >= m 或 c >= m 為 true,則程式是非良構的。
[編輯] 生成器屬性
linear_congruential_engine
的狀態大小為 1,每個狀態由一個整陣列成。
實際模數 m0 定義如下:
- 如果 m 不為零,則 m0 是 m。
- 如果 m 為零,則 m0 是 std::numeric_limits<result_type>::max() 加 1 的值(這意味著 m0 不必能表示為
result_type
)。
linear_congruential_engine
的轉換演算法為 TA(xi) = (a·xi+c) mod m0。
linear_congruential_engine
的生成演算法為 GA(xi) = (a·xi+c) mod m0。
用當前狀態生成的偽隨機數也是後續狀態。
[編輯] 預定義特化
以下特化定義了帶有兩組常用引數的隨機數引擎:
定義於標頭檔案
<random> | |
型別 | 定義 |
minstd_rand0 (C++11) |
std::linear_congruential_engine<std::uint_fast32_t, 16807, 0, 2147483647>於 1969 年由 Lewis、Goodman 和 Miller 發現,1988 年由 Park 和 Miller 採納為“最小標準” |
minstd_rand (C++11) |
std::linear_congruential_engine<std::uint_fast32_t, |
[編輯] 巢狀型別
型別 | 定義 |
result_type
|
UIntType
|
[編輯] 資料成員
constexpr UIntType multiplier [靜態] |
a (public static 成員常量) |
constexpr UIntType increment [靜態] |
c (public static 成員常量) |
constexpr UIntType modulus [靜態] |
m (public static 成員常量) |
constexpr UIntType default_seed [靜態] |
1u (public static 成員常量) |
[編輯] 成員函式
構造與播種 | |
構造引擎 (public member function) | |
設定引擎的當前狀態 (public member function) | |
生成 | |
推進引擎狀態並返回生成的值 (public member function) | |
將引擎的狀態推進指定量 (public member function) | |
特性 | |
[靜態] |
獲取輸出範圍中的最小可能值 (public static member function) |
[靜態] |
獲取輸出範圍中的最大可能值 (public static member function) |
[編輯] 非成員函式
(C++11起)(C++11起)(C++20中移除) |
比較兩個偽隨機數引擎的內部狀態 (function) |
(C++11) |
對偽隨機數引擎執行流輸入和輸出 (function template) |
[編輯] 示例
本節不完整 原因:無示例 |