Total Variation Inpainting using Split Bregman
Macros | Typedefs | Functions | Variables
randmt.h File Reference

Mersenne Twister MT19937 pseudorandom number generator. More...

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979323846264338327950288419176939937510
 The constant $ \pi $.
 
#define rand_unif_r(generator)
 Generate a uniform random number on (0,1) (reentrant) More...
 
#define rand_normal_r(generator)
 Generate a standard normal distributed random number (reentrant) More...
 
#define rand_exp_r(generator, mu)
 Generate an exponentially-distributed number (reentrant) More...
 
#define rand_geometric_r(generator, p)
 Generate a geometrically-distributed number (reentrant) More...
 
#define init_randmt(seed)   (init_randmt_r(&__randmt_global_generator, seed))
 Initialize the global generator with a seed. More...
 
#define init_randmt_auto()   (init_randmt_auto_r(&__randmt_global_generator))
 Initialize the global generator with the current time. More...
 
#define rand_uint32()   (rand_uint32_r(&__randmt_global_generator))
 Generate a random 32-bit unsigned integer (nonreentrant) More...
 
#define rand_unif()   (rand_unif_r(&__randmt_global_generator))
 Generate a uniform random number on (0,1) (nonreentrant) More...
 
#define rand_normal()   (rand_normal_r(&__randmt_global_generator))
 Generate a standard normal distributed random number (nonreentrant) More...
 
#define rand_exp(mu)   (rand_exp_r(&__randmt_global_generator, mu))
 Generate an exponentially-distributed number (nonreentrant) More...
 
#define rand_gamma(a, b)   (rand_gamma_r(&__randmt_global_generator, a, b))
 Generate a Gamma-distributed number (nonreentrant) More...
 
#define rand_poisson(mu)   (rand_poisson_r(&__randmt_global_generator, mu))
 Generate a Poisson-distributed number (nonreentrant) More...
 
#define rand_geometric(p)   (rand_geometric_r(&__randmt_global_generator, p))
 Generate a geometrically-distributed number (nonreentrant) More...
 

Typedefs

typedef struct randmtstruct_t randmt_t
 An MT19937 pseudo-random number generator. More...
 

Functions

randmt_tnew_randmt ()
 Create a new randmt_t. More...
 
void free_randmt (randmt_t *generator)
 Free a randmt_t. More...
 
void init_randmt_r (randmt_t *generator, unsigned long seed)
 Initialize randmt_t with a seed. More...
 
void init_randmt_auto_r (randmt_t *generator)
 Initialize generator with the current time and memory address. More...
 
unsigned long rand_uint32_r (randmt_t *generator)
 Generate a random 32-bit unsigned integer (reentrant) More...
 
double rand_gamma_r (randmt_t *generator, double a, double b)
 Generate a Gamma-distributed number (reentrant) More...
 
double rand_poisson_r (randmt_t *generator, double mu)
 Generate a Poisson-distributed number (reentrant) More...
 

Variables

randmt_t __randmt_global_generator
 Global randmt_t, used with the global versions of the functions.
 

Detailed Description

Mersenne Twister MT19937 pseudorandom number generator.

Warning
Do NOT use for cryptographic purposes. Read Internet RFC4086, http://tools.ietf.org/html/rfc4086.
Author
Makoto Matsumoto (1997-2002)
Takuji Nishimura (1997-2002)
Seiji Nishimura (2008) seiji.nosp@m.1976.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Nicolas Limare nicol.nosp@m.as.l.nosp@m.imare.nosp@m.@cml.nosp@m.a.ens.nosp@m.-cac.nosp@m.han.f.nosp@m.r
Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com

This software provides a high-quality pseudorandom number generator, the Mersenne Twister MT19937.

Basic Usage
To initialize the generator, call init_randmt_auto() at the beginning of the program. Example usage:
#include <stdio.h>
#include "randmt.h"
int main(void)
{
int i;
for(i = 0; i < 20; i++)
printf("%10.8f\n", rand_unif());
return 0;
}
Pseudorandom numbers can be generated for several different distributions:
Reentrant Versions
For use in multithreaded applications, reentrant versions of the functions are also included which have the same name suffixed with "_r." For these functions, the generator state is passed using a randmt_t object.

Definition in file randmt.h.

Typedef Documentation

typedef struct randmtstruct_t randmt_t

An MT19937 pseudo-random number generator.

This object represents the state of an MT19937 pseudo-random number generator. Use the following functions to create, initialize, and destroy randmt_t objects:

The randmt_t is encapsulated by forward declaration, and defined in randmt.c.

Copyright (C) 1997-2002, Makoto Matsumoto and Takuji Nishimura
Copyright (C) 2008, Seiji Nishimura seiji.nosp@m.1976.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Copyright (C) 2010-2011 Nicolas Limare nicol.nosp@m.as.l.nosp@m.imare.nosp@m.@cml.nosp@m.a.ens.nosp@m.-cac.nosp@m.han.f.nosp@m.r
Copyright (C) 2011, Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  1. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  1. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 112 of file randmt.h.