Documentation - C API
Random number generator

Table of Contents

Author:
Andrea Vedaldi

The module random.h implements random number generation in VLFeat. The generator is based on the popular Mersenne Twister algorithm [16] (which is the same as MATLAB random generator from MATLAB version 7.4 onwards).

Getting started

In VLFeat, a random number generator is implemented by an object of type VlRand. The simplest way to obtain such an object is to get the default random generator by

VlRand * rand = vl_get_rand() ;
vl_int32 signedRandomInteger = vl_rand_int31(rand) ;
@code
Note that there is one such generator per thread (see
::vl_get_rand). If more control is desired, a new ::VlRand object can
be easily created. The object is lightweight, designed to be
allocated on the stack:
@code
VlRand rand ;
vl_rand_init (&rand) ;

The generator can be seeded by vl_rand_seed and vl_rand_seed_by_array. For instance:

vl_rand_seed (&rand, clock()) ;

The generator can be used to obtain random quantities of various types:

There is no need to explicitly destroy a VlRand instance.