next up previous contents
Next: Dynamic Random Variates (dynamic_random_variate) Up: Simple Data Types and Previous: Random Sources (random_source)

   
Random Variates (random_variate)

Definition

An instance R of the data type random_variate is a non-uniform random number generator. The generation process is governed by an array<int> w. Let $[l \, .. \, r]$ be the index range of w and let W = sum_i w[i] be the total weight. Then any integer $i \in [l \, .. \, h]$ is generated with probability w[i]/W. The weight function w must be non-negative and W must be non-zero.

Creation

random_variate R(array<int> w); creates an instance R of type random_variate.

   

Operations

int R.generate() generates $i \in [l \, .. \, h]$ with probability w[i]/W.



LEDA research project
1998-10-02