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
;
|
(seit C++11) | |
Ermittelt eine Schätzung der Entropie des Zufallszahlengenerators, die ein Gleitkommawert zwischen 0 und log 2 (max()+1) ist (was gleich std:: numeric_limits < unsigned int > :: digits ist). Wenn das Gerät n Zustände hat, deren individuelle Wahrscheinlichkeiten P 0 ,...,P n-1 sind, ist die Geräteentropie S definiert als
S = −∑
n-1
i=0
P
i
log(P
i
)
Ein deterministischer Zufallszahlengenerator (z.B. ein Pseudozufallsgenerator) hat die Entropie null.
Rückgabewert
Der Wert der Geräteentropie, oder Null, falls nicht anwendbar.
Hinweise
Diese Funktion ist in einigen Standardbibliotheken nicht vollständig implementiert. Beispielsweise gibt LLVM libc++ vor Version 12 immer Null zurück, obwohl das Gerät nicht-deterministisch ist. Im Vergleich dazu gibt die Microsoft Visual C++-Implementierung immer 32 zurück, und boost.random gibt 10 zurück.
Die Entropie des Linux-Kernel-Geräts
/dev/urandom
kann mittels
ioctl RNDGETENTCNT
abgefragt werden – dies ist was
std::random_device::entropy()
in
GNU libstdc++
ab Version 8.1 verwendet.
Beispiel
Beispielausgabe auf einer der Implementierungen
#include <iostream> #include <random> int main() { std::random_device rd; std::cout << rd.entropy() << '\n'; }
Mögliche Ausgabe:
32