root/ext/mt-random/mt-random.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ScmMersenneTwister

   1 /*
   2  * mt-random.h - implements MT19937 random number generation algorithm
   3  * This code is based on Makoto Matsumoto & Takuji Nishimura's mt18837ar.c
   4  * See mt-random.c for details.
   5  * $Id: mt-random.h,v 1.6 2004/11/05 10:35:47 shirok Exp $
   6  * The original copyright notice follows.
   7  */
   8 /*
   9    A C-program for MT19937, with initialization improved 2002/1/26.
  10    Coded by Takuji Nishimura and Makoto Matsumoto.
  11 
  12    Before using, initialize the state by using init_genrand(seed)  
  13    or init_by_array(init_key, key_length).
  14 
  15    Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
  16    All rights reserved.                          
  17 
  18    Redistribution and use in source and binary forms, with or without
  19    modification, are permitted provided that the following conditions
  20    are met:
  21 
  22      1. Redistributions of source code must retain the above copyright
  23         notice, this list of conditions and the following disclaimer.
  24 
  25      2. Redistributions in binary form must reproduce the above copyright
  26         notice, this list of conditions and the following disclaimer in the
  27         documentation and/or other materials provided with the distribution.
  28 
  29      3. The names of its contributors may not be used to endorse or promote 
  30         products derived from this software without specific prior written 
  31         permission.
  32 
  33    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  34    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  35    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  36    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  41    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  43    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44 
  45 
  46    Any feedback is very welcome.
  47    http://www.math.keio.ac.jp/matumoto/emt.html
  48    email: matumoto@math.keio.ac.jp
  49 */
  50 
  51 #include "gauche.h"
  52 #include "gauche/uvector.h"
  53 #include "gauche/extend.h"
  54 
  55 #define N 624
  56 
  57 typedef struct ScmMersenneTwisterRec {
  58     SCM_HEADER;
  59     unsigned long mt[N]; /* the array for the state vector  */
  60     int mti;             /* mti==N+1 means mt[N] is not initialized */
  61 } ScmMersenneTwister;
  62 
  63 SCM_CLASS_DECL(Scm_MersenneTwisterClass);
  64 #define SCM_MERSENNE_TWISTER(obj)   ((ScmMersenneTwister*)obj)
  65 #define SCM_MERSENNE_TWISTER_P(obj) SCM_XTYPEP(obj, &Scm_MersenneTwisterClass)
  66 
  67 extern void Scm_MTInitByUI(ScmMersenneTwister *mt, unsigned long s);
  68 extern void Scm_MTInitByArray(ScmMersenneTwister *mt,
  69                               ScmInt32 init_key[],
  70                               unsigned long key_length);
  71 
  72 extern unsigned long Scm_MTGenrandU32(ScmMersenneTwister *);
  73 extern float         Scm_MTGenrandF32(ScmMersenneTwister *, int);
  74 extern double        Scm_MTGenrandF64(ScmMersenneTwister *, int);
  75 extern ScmObj        Scm_MTGenrandInt(ScmMersenneTwister *mt, ScmObj n);

/* [<][>][^][v][top][bottom][index][help] */