uniform (Discrete)
Generates random numbers uniformly distributed over the interval [a, b).
Description
The uniform class object is used in generate functions to provide random numbers uniformly distributed over the interval [a, b), where a, b are the left and right bounds of the interval respectively, and \(a, b \in Z ; a < b\).
The probability distribution is given by:
\[P(X = k) = \frac{1}{b-a}, k \in \{a, a + 1, \ldots, b-1\}\]
The cumulative distribution function is as follows:
\[\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
Syntax
namespace oneapi::mkl::rng::device {
template<typename Type, typename Method>
class uniform {
public:
using method_type = Method;
using result_type = Type;
uniform(): uniform((Type)0,
std::is_integral<Type>::value
? ((std::is_same_v<Method, uniform_method::standard> && sizeof(Type) == 32)
? (1 << 23)
: std::numeric_limits<Type>::max())
: (Type)1) {};
explicit uniform(Type a, Type b);
explicit uniform(const param_type& pt);
Type a() const;
Type b() const;
param_type param() const;
void param(const param_type& pt);
};
}
Include Files
oneapi/mkl/rng/device.hpp
Template Parameters
typename Method |
Generation method. The specific values are as follows: oneapi::mkl::rng::device::uniform_method::standard oneapi::mkl::rng::device::uniform_method::accurate See brief descriptions of the methods in Distributions Template Parameter Method. |
Input Parameters
Name |
Type |
Description |
|---|---|---|
a |
std::int8_t std::uint8_t std::int16_t std::uint16_t std::int32_t std::uint32_t std::int64_t std::uint64_t |
Left bound a |
b |
std::int8_t std::uint8_t std::int16_t std::uint16_t std::int32_t std::uint32_t std::int64_t std::uint64_t |
Right bound b |