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) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Saturation arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
Member functions | ||||
Generation | ||||
Characteristics | ||||
random_device::entropy | ||||
double entropy() const noexcept; |
(since C++11) | |
Obtains an estimate of the random number device entropy, which is a floating-point value between 0 and log2(max()+1) (which is equal to std::numeric_limits < unsigned int > :: digits ). If the device has n states whose individual probabilities are P0,...,Pn-1, the device entropy S
S = −∑n-1
i=0 Pilog(Pi)
A deterministic random number generator (e.g. a pseudo-random engine) has entropy zero.
Return value
The value of the device entropy, or zero if not applicable.
Notes
This function is not fully implemented in some standard libraries. For example, LLVM libc++ 32, and boost.random returns 10
The entropy of the Linux kernel device /dev/urandom
may be obtained using ioctl RNDGETENTCNT
— that is what std::random_device::entropy()
in GNU libstdc++
Example
Example output on one of the implementations
#include <iostream> #include <random> int main() { std::random_device rd; std::cout << rd.entropy() << '\n'; }
Possible output:
32