公共成員函式
<random>

std::random_device::entropy

double entropy() const noexcept;
返回熵
返回由operator()返回的隨機數的熵估計值。

該值以 2 為底的比例表示,值介於零和之間log2(max()+1).

如果庫實現使用隨機數引擎而不是真隨機數生成器,則此函式返回的值始終為零。

引數



返回值

生成的隨機數的熵估計值。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// random_device example
#include <iostream>
#include <random>

int main ()
{
  std::random_device rd;

  std::cout << "default random_device characteristics:" << std::endl;
  std::cout << "minimum: " << rd.min() << std::endl;
  std::cout << "maximum: " << rd.max() << std::endl;
  std::cout << "entropy: " << rd.entropy() << std::endl;
  std::cout << "a random number: " << rd() << std::endl;

  return 0;
}

可能的輸出
default random_device characteristics:
minimum: 0
maximum: 4294967295
entropy: 32
a random number: 2755249813


另見