# uniform (discrete)¶

Class is used for generation of uniformly distributed integer types random numbers.

Description

The class object is used in the oneapi::mkl::rng::generate() function 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 R; a < b$$.

The probability distribution is given by:

$P(X = k) = \frac{1}{b - a}, k \in \{a, a + 1, ... , b - 1\}$

The cumulative distribution function is as follows:

$\begin{split}F_{a, b}(x) = \left\{ \begin{array}{rcl} 0, x < a \\ \frac{\lfloor x - a + 1 \rfloor}{b-a}, a \leq x < b, x \in R \\ 1, x \ge b \end{array}\right.\end{split}$

## class uniform¶

Syntax

namespace oneapi::mkl::rng {
template<typename Method = uniform_method::by_default>
class uniform<std::int32_t, Method> {
public:
using method_type = Method;
using result_type = std::int32_t;
uniform();
explicit uniform(std::int32_t a, std::int32_t b);
std::int32_t a() const;
std::int32_t b() const;
};
}


Template parameters

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

Transformation method, which will be used for generation. Supported types:

• oneapi::mkl::rng::uniform_method::by_default

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

See description of the methods in Distributions methods template parameter.

Class Members

Routine

Description

uniform()

Default constructor

explicit uniform(std::int32_t a, std::int32_t b)

Constructor with parameters

std::int32_t a() const

Method to obtain left bound a

std::int32_t b() const

Method to obtain right bound b

Member types

method_type = Method


Description

The type which defines transformation method for generation.

result_type = std::int32_t


Description

The type which defines type of generated random numbers.

Constructors

uniform()


Description

Default constructor for distribution, parameters set as a = 0, b = std::numeric_limits<std::int32_t>::max().

uniform(std::int32_t a, std::int32_t b)


Description

Constructor with parameters. a is a left bound, b is a right bound, assume $$a < b$$.

Throws

oneapi::mkl::invalid_argument

Exception is thrown when $$a \ge b$$

Characteristics

a() const


Return Value

Returns the distribution parameter a - left bound.

b() const


Return Value

Returns the distribution parameter b - right bound.

Parent topic: Distributions