##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::random_device::entropy

From cppreference.com
< cpp‎ | numeric‎ | random‎ | random device

double entropy() const; |  | (since C++11)

Obtains an estimate of the random number device entropy, which is a floating-point value between 0 and log
2(max()+1) (which is equal to std::numeric_limits<unsigned int>::digits). If the device has n states whose individual probabilities are P
0,...,P
n-1, the device entropy S is defined as

S = -Σn-1
i=0P
ilog(P
i)

A deterministic random number generator (e.g. a pseudo-random engine) has entropy zero.

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Return value

The value of the device entropy, or zero if not applicable.

### [edit] Notes

This function is not fully implemented in some standard libraries. For example, GNU libstdc++ and LLVM libc++ always return zero even though the device is non-deterministic (for libstdc++, see bug 67578). In comparison, Microsoft Visual C++ implementation always returns 32, and boost.random returns 10.

### [edit] Example

Example output on one of the implementations

Run this code

    #include <iostream>
    #include <random>

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

Possible output:

    32

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/numeric/random/random_device/entropy&oldid=91765"
Category:

- unconditionally noexcept

Hidden categories:

- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template