類模板
<random>

std::student_t_distribution

template <class RealType = double> class student_t_distribution;
學生t分佈
根據學生t分佈生成浮點值的隨機數分佈,該分佈由以下機率密度函式描述:



此分佈將少量(n+1個值)獨立正態分佈值的歸一化結果作為隨機數。隨著樣本量的增加,該分佈逼近標準正態分佈

分佈引數n構造時設定。

要生成遵循此分佈的隨機值,請呼叫其成員函式operator()

模板引數

實數型別 (RealType)
浮點型別。別名為成員型別result_type.
預設情況下,它是double.

成員型別

以下別名是正態分佈:

成員型別定義說明
result_type第一個模板引數 (實數型別 (RealType))生成的數字型別(預設為double)
param_type未指定 (not specified)成員函式param返回的型別。

成員函式


分佈引數


非成員函式


示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// student_t_distribution
#include <iostream>
#include <random>

int main()
{
  const int nrolls=10000;  // number of experiments
  const int nstars=100;    // maximum number of stars to distribute

  // intervals definitions:
  const int nintervals=12;
  const double first=-3.0;
  const double span=0.5;

  std::default_random_engine generator;
  std::student_t_distribution<double> distribution(10.0);

  int p[nintervals]={};

  for (int i=0; i<nrolls; ++i) {
    double number = distribution(generator);
    if ((number>=first)&&(number<first+nintervals*span))
      ++p[int((number-first)/span)];
  }

  std::cout << "fisher_f_distribution (10.0):" << std::endl;
  std::cout << std::fixed; std::cout.precision(1);

  for (int i=0; i<nintervals; ++i) {
    std::cout.width(4); std::cout << (first+i*span) << "..";
    std::cout.width(4); std::cout << (first+(i+1)*span) << ": ";
    std::cout << std::string(p[i]*nstars/nrolls,'*') << std::endl;
  }

  return 0;
}

可能的輸出

student_t_distribution (10.0):
-3.0..-2.5: 
-2.5..-2.0: **
-2.0..-1.5: ****
-1.5..-1.0: *********
-1.0..-0.5: ***************
-0.5.. 0.0: ********************
 0.0.. 0.5: *********************
 0.5.. 1.0: ***************
 1.0.. 1.5: *********
 1.5.. 2.0: ****
 2.0.. 2.5: **
 2.5.. 3.0: *


另見