| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.12 Random number generators
A random generator is a machine which produces (pseudo-)random numbers.
The include file <cln/random.h> defines a class random_state
which contains the state of a random generator. If you make a copy
of the random number generator, the original one and the copy will produce
the same sequence of random numbers.
The following functions return (pseudo-)random numbers in different formats. Calling one of these modifies the state of the random number generator in a complicated but deterministic way.
random_state default_random_state
contains a default random number generator. It is used when the functions
below are called without random_state argument.
uint32 random32 (random_state& randomstate)uint32 random32 ()-
Returns a random unsigned 32-bit number. All bits are equally random.
cl_I random_I (random_state& randomstate, const cl_I& n)cl_I random_I (const cl_I& n)-
nmust be an integer > 0. This function returns a random integerxin the range0 <= x < n. cl_F random_F (random_state& randomstate, const cl_F& n)cl_F random_F (const cl_F& n)-
nmust be a float > 0. This function returns a random floating-point number of the same format asnin the range0 <= x < n. cl_R random_R (random_state& randomstate, const cl_R& n)cl_R random_R (const cl_R& n)-
Behaves like
random_Iifnis an integer and likerandom_Fifnis a float.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 27, 2013 using texi2html 5.0.
