manpagez: man pages & more
info cln
Home | html | info | man
[ << ] [ < ] [ 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.

The global variable

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)

n must be an integer > 0. This function returns a random integer x in the range 0 <= x < n.

cl_F random_F (random_state& randomstate, const cl_F& n)
cl_F random_F (const cl_F& n)

n must be a float > 0. This function returns a random floating-point number of the same format as n in the range 0 <= x < n.

cl_R random_R (random_state& randomstate, const cl_R& n)
cl_R random_R (const cl_R& n)

Behaves like random_I if n is an integer and like random_F if n is a float.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on August 27, 2013 using texi2html 5.0.

© 2000-2018
Individual documents may contain additional copyright information.