std::random_device:: entropy
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Generation | ||||
| Characteristics | ||||
|
random_device::entropy
|
||||
|
double
entropy
(
)
const
noexcept
;
|
(C++11以降) | |
乱数デバイスのエントロピーの推定値を取得します。これは 0 から log 2 (max()+1) までの浮動小数点値です(これは std:: numeric_limits < unsigned int > :: digits と等しい)。デバイスが n 個の状態を持ち、各状態の確率が P 0 ,...,P n-1 である場合、デバイスのエントロピー S は以下のように定義されます
S = −∑
n-1
i=0
P
i
log(P
i
)
決定論的乱数生成器(例:疑似乱数エンジン)のエントロピーはゼロです。
戻り値
デバイスのエントロピーの値、または該当しない場合はゼロ。
注記
この関数は一部の標準ライブラリで完全には実装されていません。例えば、 LLVM libc++ のバージョン12以前では、デバイスが非決定的であるにもかかわらず常にゼロを返します。比較すると、Microsoft Visual C++の実装は常に 32 を返し、 boost.random は 10 を返します。
Linuxカーネルデバイス
/dev/urandom
のエントロピーは、
ioctl RNDGETENTCNT
を使用して取得できます — これが
std::random_device::entropy()
関数において
GNU libstdc++
がバージョン8.1以降で使用している方法です。
例
ある実装での出力例
#include <iostream> #include <random> int main() { std::random_device rd; std::cout << rd.entropy() << '\n'; }
出力例:
32