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:
The cumulative distribution function is as follows:
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#
|
Generation method. The specific values are as follows:
See brief descriptions of the methods in Distributions Template Parameter Method. |
Note
The oneapi::mkl::rng::device::uniform_method::standard uses the float type for underlying BRNG calls. This might cause the
produced numbers to have incorrect statistics (due to rounding error) when
\((abs(b – a) > 2^{23} || abs(b) > 2^{23} || abs(a) > 2^{23})\). To get proper statistics for this case,
use the oneapi::mkl::rng::device::uniform_method::accurate method instead.
Note
For (u)int8 and (u)int16 small types, the numbers are always generated as single-precision floating-point numbers.
Input Parameters#
Name |
Type |
Description |
|---|---|---|
a |
|
Left bound |
b |
|
Right bound |
Note
The sample rejection method is used in the case of the 64-bit return type. This enables sequences to not overlap in the case of parallel generation. To ensure the output quality, provide an ample offset between engines.