Function rgsl::randist::multinomial::multinomial [] [src]

pub fn multinomial(r: &Rng, N: u32, p: &[f64], n: &mut [u32])

This function computes a random sample n[] from the multinomial distribution formed by N trials from an underlying distribution p[K]. The distribution function for n[] is,

P(n_1, n_2, ..., n_K) = (N!/(n_1! n_2! ... n_K!)) p_1n_1 p_2n_2 ... p_Kn_K

where (n_1, n_2, ..., n_K) are nonnegative integers with sum_{k=1}K n_k = N, and (p_1, p_2, ..., p_K) is a probability distribution with \sum p_i = 1. If the array p[K] is not normalized then its entries will be treated as weights and normalized appropriately. The arrays n[] and p[] must both be of length K.

Random variates are generated using the conditional binomial method (see C.S. Davis, The computer generation of multinomial random variates, Comp. Stat. Data Anal. 16 (1993) 205–217 for details).