The OpenD Programming Language

uniformDistribution

Generates a uniform probability distribution of size n, i.e., an array of size n of positive numbers of type F that sum to 1. If useThis is provided, it is used as storage.

F[]
uniformDistribution
(
F = double
)
(
size_t n
,
F[] useThis = null
)

Examples

import std.algorithm.iteration : reduce;
import std.math.operations : isClose;

auto a = uniformDistribution(5);
assert(a.length == 5);
assert(isClose(reduce!"a + b"(a), 1));

a = uniformDistribution(10, a);
assert(a.length == 10);
assert(isClose(reduce!"a + b"(a), 1));

Meta