Dynamic Random VariatesThe data type dynamic_random_variate is a random number generator that generates ints according to an arbitrary dynamic weight function. This data type is a dynamic version of Random Variates. The generation process is governed by an Remark: Dynamic Random Variates can only generate ints. ExampleThe following example shows howdynamic_random_variate can be used:
#include <LEDA/core/random_variate.h>
#include <LEDA/core/array.h>
int main()
{
leda::array<int> w(3); //weight function
w[0]=1;w[1]=2;w[2]=3;
leda::dynamic_random_variate R(w); //dynamic_random_variate
int i=R.generate(); //first random number
std::cout << i << std::endl;
R.set_weight(0,4); //set weight w[0]=4
int j=R.generate(); //second random number
std::cout << j << std::endl;
return 0;
}
The program generates a very simple weight function w and defines
a dynamic_random_variate R with weight function w.
Then it generates a random integer Finally the value |
See also:Random Variates: a non-uniform random number generator with static weight function Random Sources: a uniform random number generator |