Random SourcesThe data type random_source is a random number generator (based on the function random() from Berkeley UNIX). It can be used to generate uniformly distributed random bits, characters, ints and doubles. It can be in either of two modes:
Remark: The data type random_source is only pseudorandom. The seed depends on the internal clock. ExampleThe following program generates a random integer between 0 and 231 and outputs it.#include <LEDA/core/random_source.h> int main() { leda::random_source S; int ri; S >> ri; std::cout << ri << std::endl; return 0; } TipExtract characters and boolean values only from sources whose range spans powers of two, otherwise the distribution is not uniform. |
See also:Random Variates: non-uniform random number generator with static weight function Dynamic Random Variate: non-uniform random number generator with dynamic weight function |