std::discrete_distribution produces random integers on the interval [0, n), where the probability of each individual integer i is defined as wi/S, that is the weight of the ith integer divided by the sum of all n weights.