\doxysection{genrand.\+c}
\label{genrand_8c_source}\index{src/libsphinxbase/util/genrand.c@{src/libsphinxbase/util/genrand.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999-\/2004\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ \textcolor{comment}{/*\ }}
\DoxyCodeLine{00038\ \textcolor{comment}{\ \ \ A\ C-\/program\ for\ MT19937,\ with\ initialization\ improved\ 2002/1/26.}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ \ \ Coded\ by\ Takuji\ Nishimura\ and\ Makoto\ Matsumoto.}}
\DoxyCodeLine{00040\ \textcolor{comment}{}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ \ \ Before\ using,\ initialize\ the\ state\ by\ using\ init\_genrand(seed)\ \ }}
\DoxyCodeLine{00042\ \textcolor{comment}{\ \ \ or\ init\_by\_array(init\_key,\ key\_length).}}
\DoxyCodeLine{00043\ \textcolor{comment}{}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ \ \ Copyright\ (C)\ 1997\ -\/\ 2002,\ Makoto\ Matsumoto\ and\ Takuji\ Nishimura,}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ \ \ All\ rights\ reserved.\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }}
\DoxyCodeLine{00046\ \textcolor{comment}{}}
\DoxyCodeLine{00047\ \textcolor{comment}{\ \ \ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ \ \ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ \ \ are\ met:}}
\DoxyCodeLine{00050\ \textcolor{comment}{}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ \ \ \ \ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ \ \ \ \ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.}}
\DoxyCodeLine{00053\ \textcolor{comment}{}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ \ \ \ \ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00055\ \textcolor{comment}{\`{}\ \ \ \ \ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in\ the}}
\DoxyCodeLine{00056\ \textcolor{comment}{\ \ \ \ \ \ \ \ documentation\ and/or\ other\ materials\ provided\ with\ the\ distribution.}}
\DoxyCodeLine{00057\ \textcolor{comment}{}}
\DoxyCodeLine{00058\ \textcolor{comment}{\ \ \ \ \ 3.\ The\ names\ of\ its\ contributors\ may\ not\ be\ used\ to\ endorse\ or\ promote\ }}
\DoxyCodeLine{00059\ \textcolor{comment}{\ \ \ \ \ \ \ \ products\ derived\ from\ this\ software\ without\ specific\ prior\ written\ }}
\DoxyCodeLine{00060\ \textcolor{comment}{\ \ \ \ \ \ \ \ permission.}}
\DoxyCodeLine{00061\ \textcolor{comment}{}}
\DoxyCodeLine{00062\ \textcolor{comment}{\ \ \ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ THE\ COPYRIGHT\ HOLDERS\ AND\ CONTRIBUTORS}}
\DoxyCodeLine{00063\ \textcolor{comment}{\ \ \ "{}AS\ IS"{}\ AND\ ANY\ EXPRESS\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT}}
\DoxyCodeLine{00064\ \textcolor{comment}{\ \ \ LIMITED\ TO,\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR}}
\DoxyCodeLine{00065\ \textcolor{comment}{\ \ \ A\ PARTICULAR\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ THE\ COPYRIGHT\ OWNER\ OR}}
\DoxyCodeLine{00066\ \textcolor{comment}{\ \ \ CONTRIBUTORS\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,\ SPECIAL,}}
\DoxyCodeLine{00067\ \textcolor{comment}{\ \ \ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ LIMITED\ TO,}}
\DoxyCodeLine{00068\ \textcolor{comment}{\ \ \ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ DATA,\ OR}}
\DoxyCodeLine{00069\ \textcolor{comment}{\ \ \ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ THEORY\ OF}}
\DoxyCodeLine{00070\ \textcolor{comment}{\ \ \ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ (INCLUDING}}
\DoxyCodeLine{00071\ \textcolor{comment}{\ \ \ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ OF\ THIS}}
\DoxyCodeLine{00072\ \textcolor{comment}{\ \ \ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00073\ \textcolor{comment}{}}
\DoxyCodeLine{00074\ \textcolor{comment}{}}
\DoxyCodeLine{00075\ \textcolor{comment}{\ \ \ Any\ feedback\ is\ very\ welcome.}}
\DoxyCodeLine{00076\ \textcolor{comment}{\ \ \ http://www.math.keio.ac.jp/matumoto/emt.html}}
\DoxyCodeLine{00077\ \textcolor{comment}{\ \ \ email:\ matumoto@math.keio.ac.jp}}
\DoxyCodeLine{00078\ \textcolor{comment}{*/}}
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00080\ }
\DoxyCodeLine{00081\ \textcolor{comment}{/*}}
\DoxyCodeLine{00082\ \textcolor{comment}{\ *\ randgen.c\ \ \ :\ a\ portable\ random\ generator\ }}
\DoxyCodeLine{00083\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00084\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00085\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00086\ \textcolor{comment}{\ *\ CMU\ ARPA\ Speech\ Project}}
\DoxyCodeLine{00087\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00088\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999\ Carnegie\ Mellon\ University.}}
\DoxyCodeLine{00089\ \textcolor{comment}{\ *\ ALL\ RIGHTS\ RESERVED.}}
\DoxyCodeLine{00090\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00091\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00092\ \textcolor{comment}{\ *\ HISTORY}}
\DoxyCodeLine{00093\ \textcolor{comment}{\ *\ \$Log:\ genrand.c,v\ \$}}
\DoxyCodeLine{00094\ \textcolor{comment}{\ *\ Revision\ 1.2\ \ 2005/06/22\ 03:01:50\ \ arthchan2003}}
\DoxyCodeLine{00095\ \textcolor{comment}{\ *\ Added\ \ keyword}}
\DoxyCodeLine{00096\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00097\ \textcolor{comment}{\ *\ Revision\ 1.3\ \ 2005/03/30\ 01:22:48\ \ archan}}
\DoxyCodeLine{00098\ \textcolor{comment}{\ *\ Fixed\ mistakes\ in\ last\ updates.\ Add}}
\DoxyCodeLine{00099\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00100\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00101\ \textcolor{comment}{\ *\ 18-\/Nov-\/04\ ARCHAN\ (archan@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00102\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ First\ incorporated\ from\ the\ Mersenne\ Twister\ Random}}
\DoxyCodeLine{00103\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Number\ Generator\ package.\ It\ was\ chosen\ because\ it\ is}}
\DoxyCodeLine{00104\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ in\ BSD-\/license\ and\ its\ performance\ is\ quite}}
\DoxyCodeLine{00105\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ reasonable.\ Of\ course\ if\ you\ look\ at\ the\ inventors's}}
\DoxyCodeLine{00106\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ page.\ \ This\ random\ generator\ can\ actually\ gives}}
\DoxyCodeLine{00107\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ 19937-\/bits\ period.\ \ This\ is\ already\ far\ from\ we\ need.\ }}
\DoxyCodeLine{00108\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ This\ will\ possibly\ good\ enough\ for\ the\ next\ 10\ years.\ }}
\DoxyCodeLine{00109\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00110\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ I\ also\ downgrade\ the\ code\ a\ little\ bit\ to\ avoid\ Sphinx's}}
\DoxyCodeLine{00111\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ developers\ misused\ it.\ }}
\DoxyCodeLine{00112\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00113\ }
\DoxyCodeLine{00114\ }
\DoxyCodeLine{00115\ }
\DoxyCodeLine{00116\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/genrand.h"{}}}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \textcolor{comment}{/*\ Period\ parameters\ */}}
\DoxyCodeLine{00121\ \textcolor{preprocessor}{\#define\ N\ 624}}
\DoxyCodeLine{00122\ \textcolor{preprocessor}{\#define\ M\ 397}}
\DoxyCodeLine{00123\ \textcolor{preprocessor}{\#define\ MATRIX\_A\ 0x9908b0dfUL\ \ \ }\textcolor{comment}{/*\ constant\ vector\ a\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00124\ \textcolor{preprocessor}{\#define\ UPPER\_MASK\ 0x80000000UL\ }\textcolor{comment}{/*\ most\ significant\ w-\/r\ bits\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00125\ \textcolor{preprocessor}{\#define\ LOWER\_MASK\ 0x7fffffffUL\ }\textcolor{comment}{/*\ least\ significant\ r\ bits\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \textcolor{keywordtype}{void}\ init\_genrand(\textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ s);}
\DoxyCodeLine{00128\ }
\DoxyCodeLine{00129\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00130\ genrand\_seed(\textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ s)}
\DoxyCodeLine{00131\ \{}
\DoxyCodeLine{00132\ \ \ \ \ init\_genrand(s);}
\DoxyCodeLine{00133\ \}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ }
\DoxyCodeLine{00136\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ mt[N];\ \ \ \ \ \textcolor{comment}{/*\ the\ array\ for\ the\ state\ vector\ \ */}}
\DoxyCodeLine{00137\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ mti\ =\ N\ +\ 1;\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ mti==N+1\ means\ mt[N]\ is\ not\ initialized\ */}}
\DoxyCodeLine{00138\ }
\DoxyCodeLine{00139\ \textcolor{comment}{/*\ initializes\ mt[N]\ with\ a\ seed\ */}}
\DoxyCodeLine{00140\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00141\ init\_genrand(\textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ s)}
\DoxyCodeLine{00142\ \{}
\DoxyCodeLine{00143\ \ \ \ \ mt[0]\ =\ s\ \&\ 0xffffffffUL;}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{for}\ (mti\ =\ 1;\ mti\ <\ N;\ mti++)\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ mt[mti]\ =}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \ \ \ \ (1812433253UL\ *\ (mt[mti\ -\/\ 1]\ \string^\ (mt[mti\ -\/\ 1]\ >>\ 30))\ +\ mti);}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ See\ Knuth\ TAOCP\ Vol2.\ 3rd\ Ed.\ P.106\ for\ multiplier.\ */}}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ In\ the\ previous\ versions,\ MSBs\ of\ the\ seed\ affect\ \ \ */}}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ only\ MSBs\ of\ the\ array\ mt[].\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ */}}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ 2002/01/09\ modified\ by\ Makoto\ Matsumoto\ \ \ \ \ \ \ \ \ \ \ \ \ */}}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ mt[mti]\ \&=\ 0xffffffffUL;}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ for\ >32\ bit\ machines\ */}}
\DoxyCodeLine{00153\ \ \ \ \ \}}
\DoxyCodeLine{00154\ \}}
\DoxyCodeLine{00155\ }
\DoxyCodeLine{00156\ \textcolor{comment}{/*\ generates\ a\ random\ number\ on\ [0,0xffffffff]-\/interval\ */}}
\DoxyCodeLine{00157\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}}
\DoxyCodeLine{00158\ genrand\_int32(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00159\ \{}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ y;}
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ mag01[2]\ =\ \{\ 0x0UL,\ MATRIX\_A\ \};}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{comment}{/*\ mag01[x]\ =\ x\ *\ MATRIX\_A\ \ for\ x=0,1\ */}}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \ \ \ \ \textcolor{keywordflow}{if}\ (mti\ >=\ N)\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ generate\ N\ words\ at\ one\ time\ */}}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ kk;}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (mti\ ==\ N\ +\ 1)\ \ \ \ \ \ \ \textcolor{comment}{/*\ if\ init\_genrand()\ has\ not\ been\ called,\ */}}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ \ \ \ \ init\_genrand(5489UL);\ \ \ \ \ \ \ \textcolor{comment}{/*\ a\ default\ initial\ seed\ is\ used\ */}}
\DoxyCodeLine{00169\ }
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (kk\ =\ 0;\ kk\ <\ N\ -\/\ M;\ kk++)\ \{}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \ \ \ \ y\ =\ (mt[kk]\ \&\ UPPER\_MASK)\ |\ (mt[kk\ +\ 1]\ \&\ LOWER\_MASK);}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \ \ \ \ mt[kk]\ =\ mt[kk\ +\ M]\ \string^\ (y\ >>\ 1)\ \string^\ mag01[y\ \&\ 0x1UL];}
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (;\ kk\ <\ N\ -\/\ 1;\ kk++)\ \{}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \ \ \ \ y\ =\ (mt[kk]\ \&\ UPPER\_MASK)\ |\ (mt[kk\ +\ 1]\ \&\ LOWER\_MASK);}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \ \ \ \ mt[kk]\ =\ mt[kk\ +\ (M\ -\/\ N)]\ \string^\ (y\ >>\ 1)\ \string^\ mag01[y\ \&\ 0x1UL];}
\DoxyCodeLine{00177\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ y\ =\ (mt[N\ -\/\ 1]\ \&\ UPPER\_MASK)\ |\ (mt[0]\ \&\ LOWER\_MASK);}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ mt[N\ -\/\ 1]\ =\ mt[M\ -\/\ 1]\ \string^\ (y\ >>\ 1)\ \string^\ mag01[y\ \&\ 0x1UL];}
\DoxyCodeLine{00180\ }
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ mti\ =\ 0;}
\DoxyCodeLine{00182\ \ \ \ \ \}}
\DoxyCodeLine{00183\ }
\DoxyCodeLine{00184\ \ \ \ \ y\ =\ mt[mti++];}
\DoxyCodeLine{00185\ }
\DoxyCodeLine{00186\ \ \ \ \ \textcolor{comment}{/*\ Tempering\ */}}
\DoxyCodeLine{00187\ \ \ \ \ y\ \string^=\ (y\ >>\ 11);}
\DoxyCodeLine{00188\ \ \ \ \ y\ \string^=\ (y\ <<\ 7)\ \&\ 0x9d2c5680UL;}
\DoxyCodeLine{00189\ \ \ \ \ y\ \string^=\ (y\ <<\ 15)\ \&\ 0xefc60000UL;}
\DoxyCodeLine{00190\ \ \ \ \ y\ \string^=\ (y\ >>\ 18);}
\DoxyCodeLine{00191\ }
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{keywordflow}{return}\ y;}
\DoxyCodeLine{00193\ \}}
\DoxyCodeLine{00194\ }
\DoxyCodeLine{00195\ \textcolor{comment}{/*\ generates\ a\ random\ number\ on\ [0,0x7fffffff]-\/interval\ */}}
\DoxyCodeLine{00196\ \textcolor{keywordtype}{long}}
\DoxyCodeLine{00197\ genrand\_int31(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00198\ \{}
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{keywordflow}{return}\ (\textcolor{keywordtype}{long})\ (genrand\_int32()\ >>\ 1);}
\DoxyCodeLine{00200\ \}}
\DoxyCodeLine{00201\ }
\DoxyCodeLine{00202\ \textcolor{comment}{/*\ generates\ a\ random\ number\ on\ [0,1]-\/real-\/interval\ */}}
\DoxyCodeLine{00203\ \textcolor{keywordtype}{double}}
\DoxyCodeLine{00204\ genrand\_real1(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00205\ \{}
\DoxyCodeLine{00206\ \ \ \ \ \textcolor{keywordflow}{return}\ genrand\_int32()\ *\ (1.0\ /\ 4294967295.0);}
\DoxyCodeLine{00207\ \ \ \ \ \textcolor{comment}{/*\ divided\ by\ 2\string^32-\/1\ */}}
\DoxyCodeLine{00208\ \}}
\DoxyCodeLine{00209\ }
\DoxyCodeLine{00210\ \textcolor{comment}{/*\ generates\ a\ random\ number\ on\ [0,1)-\/real-\/interval\ */}}
\DoxyCodeLine{00211\ \textcolor{keywordtype}{double}}
\DoxyCodeLine{00212\ genrand\_real2(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00213\ \{}
\DoxyCodeLine{00214\ \ \ \ \ \textcolor{keywordflow}{return}\ genrand\_int32()\ *\ (1.0\ /\ 4294967296.0);}
\DoxyCodeLine{00215\ \ \ \ \ \textcolor{comment}{/*\ divided\ by\ 2\string^32\ */}}
\DoxyCodeLine{00216\ \}}
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00218\ \textcolor{comment}{/*\ generates\ a\ random\ number\ on\ (0,1)-\/real-\/interval\ */}}
\DoxyCodeLine{00219\ \textcolor{keywordtype}{double}}
\DoxyCodeLine{00220\ genrand\_real3(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00221\ \{}
\DoxyCodeLine{00222\ \ \ \ \ \textcolor{keywordflow}{return}\ (((\textcolor{keywordtype}{double})\ genrand\_int32())\ +\ 0.5)\ *\ (1.0\ /\ 4294967296.0);}
\DoxyCodeLine{00223\ \ \ \ \ \textcolor{comment}{/*\ divided\ by\ 2\string^32\ */}}
\DoxyCodeLine{00224\ \}}
\DoxyCodeLine{00225\ }
\DoxyCodeLine{00226\ \textcolor{comment}{/*\ generates\ a\ random\ number\ on\ [0,1)\ with\ 53-\/bit\ resolution*/}}
\DoxyCodeLine{00227\ \textcolor{keywordtype}{double}}
\DoxyCodeLine{00228\ genrand\_res53(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00229\ \{}
\DoxyCodeLine{00230\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ a\ =\ genrand\_int32()\ >>\ 5,\ b\ =\ genrand\_int32()\ >>\ 6;}
\DoxyCodeLine{00231\ \ \ \ \ \textcolor{keywordflow}{return}\ (a\ *\ 67108864.0\ +\ b)\ *\ (1.0\ /\ 9007199254740992.0);}
\DoxyCodeLine{00232\ \}}
\DoxyCodeLine{00233\ }
\DoxyCodeLine{00234\ \textcolor{comment}{/*\ These\ real\ versions\ are\ due\ to\ Isaku\ Wada,\ 2002/01/09\ added\ */}}

\end{DoxyCode}
