名稱空間
變體
操作

std::subtract_with_carry_engine

來自 cppreference.com
< cpp‎ | 數值‎ | 隨機
 
 
 
 
 
定義於標頭檔案 <random>
template<

    class UIntType,
    std::size_t w, std::size_t s, std::size_t r

> class subtract_with_carry_engine;
(C++11 起)

是一個使用帶進位減法演算法的隨機數引擎。

目錄

[編輯] 模板引數

UIntType - 生成器產生的結果型別。如果這不是 unsigned shortunsigned intunsigned longunsigned long long 之一,則效果是未定義的。
w - 狀態序列的字大小,以位為單位
s - 短滯後
r - 長滯後

如果 w 不在 [1std::numeric_limits<UIntType>::digits] 範圍內,或者 s 不在 [1r) 範圍內,則程式格式錯誤。

[編輯] 生成器屬性

subtract_with_carry_engine 狀態的大小O(r),每個狀態由兩部分組成

  • 一個包含 r 個整數值的序列 X,其中每個值都在 [02w
    )
    範圍內。
  • 一個整數 c(稱為進位),其值為 01

給定 Xj 代表 X 的第 j mod r 個值(從 0 開始),subtract_with_carry_engine轉換演算法TA(xi))定義如下

  1. YXi-s-Xi-r-c
  2. yY mod 2w
    ,並將 Xi 設定為 y
  3. 如果 Y 為負,則將 c 設定為 1,否則將 c 設定為 0

subtract_with_carry_engine生成演算法GA(xi) = y,其中 y 是轉換演算法第 2 步中產生的值。

[編輯] 預定義特化

以下特化定義了帶有兩組常用引數的隨機數引擎:

定義於標頭檔案 <random>
型別 定義
ranlux24_base (C++11) std::subtract_with_carry_engine<std::uint_fast32_t, 24, 10, 24>[編輯]
ranlux48_base (C++11) std::subtract_with_carry_engine<std::uint_fast64_t, 48, 5, 12>[編輯]

[編輯] 巢狀型別

型別 定義
result_type UIntType

[編輯] 資料成員

constexpr std::size_t word_size
[靜態]
w
(public static 成員常量)
constexpr std::size_t short_lag
[靜態]
s
(public static 成員常量)
constexpr std::size_t long_lag
[靜態]
r
(public static 成員常量)
constexpr std::uint_least32_t default_seed
[靜態]
19780503u
(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中移除)
比較兩個偽隨機數引擎的內部狀態
(函式) [編輯]
對偽隨機數引擎執行流輸入和輸出
(函式模板) [編輯]

[編輯] 示例

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 3809 C++11 default_seed 可能無法
result_type 表示
更改其型別為
std::uint_least32_t