成員函式
<random>

std::cauchy_distribution::operator()

(1)
template<class URNG>result_type operator()(URNG& g);
(2)
template<class URNG>result_type operator()(URNG& g, const param_type& parm);
生成隨機數
返回一個遵循物件關聯的分佈引數(版本1)或由parm指定的引數(版本2)的新的隨機數。

生成器物件(g)透過其operator()成員函式。該 cauchy_distribution 物件轉換由此獲得的這些值,以便對該成員函式使用相同的引數進行連續呼叫會產生遵循具有適當引數的柯西分佈的浮點值。

引數

g
一個均勻隨機數生成器物件,用作隨機性源。
URNG應為均勻隨機數生成器型別,例如標準生成器類之一。
parm
一個表示分佈引數的物件,透過呼叫成員函式param獲得。
param_type是一個成員型別。

返回值

A new random number. (一個新的隨機數。)
result_type是一個成員型別,定義為第一個類模板引數的別名 (實數型別 (RealType)).

示例

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

int main()
{
  // construct a trivial random generator engine from a time-based seed:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  std::default_random_engine generator (seed);

  std::cauchy_distribution<double> distribution (0.0,1.0);

  std::cout << "some Cauchy-distributed(0.0,1.0) results:" << std::endl;
  for (int i=0; i<5; ++i)
    std::cout << distribution(generator) << std::endl;

  return 0;
}

可能的輸出
some Cauchy-distributed(0.0,1.0) results:
-1.27751
0.124077
0.678413
0.193006
-2.53555


複雜度

攤銷常數(對g.operator()).

另見