Namespaces
Variants

std::random_device::entropy

From cppreference.com
 
 
 
 
 
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 is defined as

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

Before v8, libstdc++ always returned 0. Before v12, libc++ always returned 0. vc++ always returns 32.

The entropy of the Linux kernel device /dev/urandom may be obtained using ioctl RNDGETENTCNT, which is what libstdc++ and libc++ use since v8 and v12, respectively, if available.

Example

#include <iostream>
#include <random>

int main()
{
    std::random_device rd;
    std::cout << rd.entropy() << '\n';
}

Possible output:

32