include/it/random.h

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 /*
00020 A C-program for MT19937, with initialization improved 2002/2/10.
00021 Coded by Takuji Nishimura and Makoto Matsumoto.
00022 This is a faster version by taking Shawn Cokus's optimization,
00023 Matthe Bellew's simplification, Isaku Wada's real version.
00024 
00025 Before using, initialize the state by using init_genrand(seed) 
00026 or init_by_array(init_key, key_length).
00027 
00028 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
00029 All rights reserved.                          
00030 
00031 Redistribution and use in source and binary forms, with or without
00032 modification, are permitted provided that the following conditions
00033 are met:
00034 
00035 1. Redistributions of source code must retain the above copyright
00036 notice, this list of conditions and the following disclaimer.
00037 
00038 2. Redistributions in binary form must reproduce the above copyright
00039 notice, this list of conditions and the following disclaimer in the
00040 documentation and/or other materials provided with the distribution.
00041 
00042 3. The names of its contributors may not be used to endorse or promote 
00043 products derived from this software without specific prior written 
00044 permission.
00045 
00046 The original code is located at: 
00047 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/MTARCOK/mt19937ar-cok.c 
00048 
00049 It was licensed under the terms of the BSD license. 
00050 
00051 */
00052 
00053 /*
00054   Random number generator
00055   Copyright (C) 2005 Vivien Chappelier
00056   Copyright (C) 2006 François Cayre 
00057 */
00058 
00059 #ifndef __it_random_h
00060 #define __it_random_h
00061 
00062 #include <it/vec.h>
00063 #include <it/mat.h>
00064 
00065 /*---------------------------------------------------------------------------*/
00066 /*! \defgroup rand Random generator                                          */
00067 /* @{                                                                        */
00068 /*---------------------------------------------------------------------------*/
00069 
00070 
00071 /* MT19937cok-ar related functions: they are here for providing   */
00072 /* additional features to whoever might need it                   */
00073 void mt19937_srand (unsigned int seed);
00074 void mt19937_srand_by_array (unsigned int init_key[],
00075            unsigned int key_length);
00076 /* generates a random number on [0,0xffffffff]-interval */
00077 unsigned int mt19937_rand_int32 (void);
00078 /* generates a random number on [0,0x7fffffff]-interval */
00079 int  mt19937_rand_int31 (void);
00080 /* generates a random number on [0,1]-real-interval */
00081 double mt19937_rand_real1 (void);
00082 /* generates a random number on [0,1)-real-interval */
00083 double mt19937_rand_real2 (void);
00084 /* generates a random number on (0,1)-real-interval */
00085 double mt19937_rand_real3 (void);
00086 /* generates a random number on [0,1) with 53-bit resolution*/
00087 double mt19937_rand_res53 (void);
00088 
00089 
00090 /* initialize the random number generator (with a random seed)    */
00091 /* Note: the seed is taken from the milliseconds of the current   */
00092 /* time, which is not a serious option for security applications. */
00093 /* In this case, always use it_seed with your favorite method     */
00094 /* to obtain a good seed.                                         */
00095 void it_randomize (void);
00096 
00097 /* intializes the random generator from a seed */
00098 void it_seed (int seed);
00099 
00100 /* generate a value uniformly distributed in [0,1[ */
00101 double it_rand (void);
00102 
00103 /* generate a value distributed normally */
00104 double it_randn (void);
00105 
00106 /* generate a random variable from its probability
00107    density function using the acceptance-rejection method.
00108    the pdf is assumed to be zero outside [a, b].
00109 */
00110 double it_randpdf (double a, double b, it_function_t pdf, it_args_t args);
00111 
00112 
00113 /* Random variable that follows a memoryless pdf */
00114 int  it_rand_memoryless (vec pdf);
00115 
00116 /* @} */
00117 
00118 #endif

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau