uniform (離散)#

区間 [a, b) にわたって均一に分布する乱数を生成します。

説明#

uniform クラス・オブジェクトは、区間 [a, b) に均一に分布する乱数を生成するため generate 関数で使用されます。ここで、a、b はそれぞれ区間の左境界と右境界であり、\(a, b \in Z ; a < b\) です。

確率分布は次のように表されます。

\[ \begin{align}\begin{aligned}P(X = k) = \frac{1}{b-a}\\k \in \{a, a + 1, \ldots, b-1\}\end{aligned}\end{align} \]

累積分布関数は次のようになります。

\[\begin{split}F_{a, b}(x) = \begin{cases} 0, & x < a \\ \frac{x-a + 1}{b-a}, & a \leq x < b \\ 1, & x \geq b \end{cases}, x \in R\end{split}\]

API#

構文#

namespace oneapi::mkl::rng { 
  template<typename Method> 
  class uniform<std::(u)int32_t, Method> { 
  public: 
    using method_type = Method; 
    using result_type = std::(u)int32_t; 

    uniform(): uniform((std::(u)int32_t )(0), 
                       std::is_same<Method, 
                       uniform_method::standard>::value ? (1 << 23) : 
                       std::numeric_limits<Type>::max()){} 
    explicit uniform(std::(u)int32_t a, std::(u)int32_t b); 
    explicit uniform(const param_type& pt); 

    std::(u)int32_t a() const; 
    std::(u)int32_t b() const; 
    param_type param() const; 
    void param(const param_type& pt); 
  }; 
}

サポートされるデバイス: CPU と GPU。

インクルード・ファイル#

  • oneapi/mkl/rng.hpp

テンプレート・パラメーター#

typename Method = oneapi::mkl::rng::uniform_method::by_default

生成メソッド。固有の値は次のとおりです:

oneapi::mkl::rng::uniform_method::standard

oneapi::mkl::rng::uniform_method::accurate

配布テンプレート・パラメーター・メソッドのメソッドの説明を参照してください。

oneapi::mkl::rng::uniform_method::standard は、GPU デバイスで s BRNG タイプを使用します。これにより、\((abs(b – a) > 2^{23} || abs(b) > 2^{23} || abs(a) > 2^{23})\) の場合、生成された数値の統計が不正確になる可能性があります (丸め誤差のため)。この場合、適切な統計を取得するには oneapi::mkl::rng::uniform_method::accurate メソッドを使用します。

入力パラメーター#

名前

タイプ

説明

a

std::int32_t

std::uint32_t

左境界 a

b

std::int32_t

std::uint32_t

右境界 b