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
)
결정론적 난수 생성기(예: 의사 난수 엔진)의 엔트로피는 0입니다.
반환값
디바이스 엔트로피 값, 또는 해당되지 않을 경우 0입니다.
참고 사항
이 함수는 일부 표준 라이브러리에서 완전히 구현되지 않았습니다. 예를 들어, LLVM libc++ 버전 12 이전에서는 장치가 비결정적임에도 불구하고 항상 0을 반환합니다. 비교해보면, Microsoft Visual C++ 구현체는 항상 32 를 반환하고, boost.random 은 10 을 반환합니다.
리눅스 커널 장치
/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