\hypertarget{structMT19937}{
\subsection{MT19937 Struct Reference}
\label{structMT19937}\index{MT19937@{MT19937}}
}


Useful wrapper for \hyperlink{structMT19937}{MT19937} random number generator class.  




{\ttfamily \#include $<$mt19937.h$>$}

\subsubsection*{Classes}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{structMT19937_1_1ParseError}{ParseError}
\begin{DoxyCompactList}\small\item\em Null struct thrown if attempting to load state from stream yields a parse error. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{structMT19937_a4a5fb0971f31767fab0e8a578ecb6590}{MT19937} ()
\item 
void \hyperlink{structMT19937_af4600dda34a35d04ef9558065424f203}{simple\_\-seed} (int seed)
\item 
void \hyperlink{structMT19937_a80622e803a5429229b8b72035916da51}{copy\_\-state} (const \hyperlink{structMT19937}{MT19937} \&r)
\item 
double \hyperlink{structMT19937_a12847435d58a426060af9e2ca3b9e052}{operator()} ()
\item 
\hyperlink{randomc_8h_a435d1572bf3f880d55459d9805097f62}{uint32\_\-t} \hyperlink{structMT19937_a79b46267605469a1900c5f6bff35d528}{rand\_\-int} ()
\item 
double \hyperlink{structMT19937_adb5008d1485f7ba8413c6ff8b3701f31}{gaussian} ()
\item 
void \hyperlink{structMT19937_a5e8d72adda20f212d4a41a910e680f48}{write} (std::ostream \&o)
\item 
void \hyperlink{structMT19937_a69e3e0f1dcd24ad2ea1eed1a19c79a08}{read} (std::istream \&is)
\end{DoxyCompactItemize}
\subsubsection*{Public Attributes}
\begin{DoxyCompactItemize}
\item 
CRandomMersenne \hyperlink{structMT19937_a5ae365b3da2b617913bc60e3ac98f2e4}{rng}
\end{DoxyCompactItemize}
\subsubsection*{Private Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{structMT19937_abab84cb4be11be2ba708b9623d7aa4c0}{MT19937} (const \hyperlink{structMT19937}{MT19937} \&)
\end{DoxyCompactItemize}


\subsubsection{Detailed Description}
Useful wrapper for \hyperlink{structMT19937}{MT19937} random number generator class. 

Definition at line 32 of file mt19937.h.



\subsubsection{Constructor \& Destructor Documentation}
\hypertarget{structMT19937_a4a5fb0971f31767fab0e8a578ecb6590}{
\index{MT19937@{MT19937}!MT19937@{MT19937}}
\index{MT19937@{MT19937}!MT19937@{MT19937}}
\paragraph[{MT19937}]{\setlength{\rightskip}{0pt plus 5cm}MT19937::MT19937 (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_a4a5fb0971f31767fab0e8a578ecb6590}


Definition at line 42 of file mt19937.h.


\begin{DoxyCode}
        :rng(0)
        {}
\end{DoxyCode}
\hypertarget{structMT19937_abab84cb4be11be2ba708b9623d7aa4c0}{
\index{MT19937@{MT19937}!MT19937@{MT19937}}
\index{MT19937@{MT19937}!MT19937@{MT19937}}
\paragraph[{MT19937}]{\setlength{\rightskip}{0pt plus 5cm}MT19937::MT19937 (
\begin{DoxyParamCaption}
\item[{const {\bf MT19937} \&}]{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{structMT19937_abab84cb4be11be2ba708b9623d7aa4c0}


Disallow copying, since one almost never wants to do this. 

Copying has to be explicit via \hyperlink{structMT19937_a80622e803a5429229b8b72035916da51}{MT19937::copy\_\-state()}. 

\subsubsection{Member Function Documentation}
\hypertarget{structMT19937_af4600dda34a35d04ef9558065424f203}{
\index{MT19937@{MT19937}!simple\_\-seed@{simple\_\-seed}}
\index{simple\_\-seed@{simple\_\-seed}!MT19937@{MT19937}}
\paragraph[{simple\_\-seed}]{\setlength{\rightskip}{0pt plus 5cm}void MT19937::simple\_\-seed (
\begin{DoxyParamCaption}
\item[{int}]{seed}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_af4600dda34a35d04ef9558065424f203}


Seed state with a simple RNG. 


\begin{DoxyParams}{Parameters}
{\em seed} & \\
\hline
\end{DoxyParams}


Definition at line 48 of file mt19937.h.



References rng.


\begin{DoxyCode}
        {
            rng.RandomInit(seed);
        }
\end{DoxyCode}
\hypertarget{structMT19937_a80622e803a5429229b8b72035916da51}{
\index{MT19937@{MT19937}!copy\_\-state@{copy\_\-state}}
\index{copy\_\-state@{copy\_\-state}!MT19937@{MT19937}}
\paragraph[{copy\_\-state}]{\setlength{\rightskip}{0pt plus 5cm}void MT19937::copy\_\-state (
\begin{DoxyParamCaption}
\item[{const {\bf MT19937} \&}]{r}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_a80622e803a5429229b8b72035916da51}


Duplicate RNG state. 


\begin{DoxyParams}{Parameters}
{\em r} & RNG to duplicate \\
\hline
\end{DoxyParams}


Definition at line 55 of file mt19937.h.



References rng.


\begin{DoxyCode}
        {
            rng = r.rng;
        }
\end{DoxyCode}
\hypertarget{structMT19937_a12847435d58a426060af9e2ca3b9e052}{
\index{MT19937@{MT19937}!operator()@{operator()}}
\index{operator()@{operator()}!MT19937@{MT19937}}
\paragraph[{operator()}]{\setlength{\rightskip}{0pt plus 5cm}double MT19937::operator() (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_a12847435d58a426060af9e2ca3b9e052}


Generate a double. 



Definition at line 61 of file mt19937.h.



References rng.


\begin{DoxyCode}
        {
            return rng.Random();
        }
\end{DoxyCode}
\hypertarget{structMT19937_a79b46267605469a1900c5f6bff35d528}{
\index{MT19937@{MT19937}!rand\_\-int@{rand\_\-int}}
\index{rand\_\-int@{rand\_\-int}!MT19937@{MT19937}}
\paragraph[{rand\_\-int}]{\setlength{\rightskip}{0pt plus 5cm}{\bf uint32\_\-t} MT19937::rand\_\-int (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_a79b46267605469a1900c5f6bff35d528}


Generate an int. 



Definition at line 67 of file mt19937.h.



References rng.


\begin{DoxyCode}
        {
            return rng.BRandom();
        }
\end{DoxyCode}
\hypertarget{structMT19937_adb5008d1485f7ba8413c6ff8b3701f31}{
\index{MT19937@{MT19937}!gaussian@{gaussian}}
\index{gaussian@{gaussian}!MT19937@{MT19937}}
\paragraph[{gaussian}]{\setlength{\rightskip}{0pt plus 5cm}double MT19937::gaussian (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_adb5008d1485f7ba8413c6ff8b3701f31}


Generate a Gaussian variate. 



Definition at line 73 of file mt19937.h.


\begin{DoxyCode}
        {
            double x1, x2, w;
            do {
                x1 = 2.0 * (*this)() - 1.0;
                x2 = 2.0 * (*this)() - 1.0;
                w = x1 * x1 + x2 * x2;
            } while ( w >= 1.0 );

            w = std::sqrt( (-2.0 * std::log( w ) ) / w );
            return x1 * w;
            //spare so we don't have to save that one extra bit of state y2 = x2 
      * w;
        }
\end{DoxyCode}
\hypertarget{structMT19937_a5e8d72adda20f212d4a41a910e680f48}{
\index{MT19937@{MT19937}!write@{write}}
\index{write@{write}!MT19937@{MT19937}}
\paragraph[{write}]{\setlength{\rightskip}{0pt plus 5cm}void MT19937::write (
\begin{DoxyParamCaption}
\item[{std::ostream \&}]{o}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_a5e8d72adda20f212d4a41a910e680f48}


Serialise state. 


\begin{DoxyParams}{Parameters}
{\em o} & Stream to serialise to \\
\hline
\end{DoxyParams}


Definition at line 89 of file mt19937.h.



References rng.


\begin{DoxyCode}
        {
            using namespace std;
            char f = o.fill();
            ios_base::fmtflags fl = o.flags();
            o << "MT19937 " << hex << setfill('0') << setw(3) << rng.get_index();
          
            for(int i=0; i < MERS_N; i++)
                o << " " << hex << setw(8) << rng.get_state()[i];
            
            o << setfill(f) << setiosflags(fl);
        }
\end{DoxyCode}
\hypertarget{structMT19937_a69e3e0f1dcd24ad2ea1eed1a19c79a08}{
\index{MT19937@{MT19937}!read@{read}}
\index{read@{read}!MT19937@{MT19937}}
\paragraph[{read}]{\setlength{\rightskip}{0pt plus 5cm}void MT19937::read (
\begin{DoxyParamCaption}
\item[{std::istream \&}]{is}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{structMT19937_a69e3e0f1dcd24ad2ea1eed1a19c79a08}


De serialise state param is Stream to de-\/serialise from. 



Definition at line 103 of file mt19937.h.



References rng.


\begin{DoxyCode}
        {
            using namespace std;

            string ls;
            getline(is, ls);
            if(ls.size() != 5627)
            {
                cerr << "MT19937: Expected string of length 5627. Got " << ls.siz
      e() << endl;
                throw ParseError();
            }

            istringstream l(ls);
            
            string s;
            uint32_t i;

            l >> s;
            
            if(s != "MT19937")
            {   
                cerr << "MT19937: Expected MT19937. Got " << s << endl;
                throw ParseError();
            }       

            for(int n=0; n < MERS_N + 1; n++)
            {
                l >> hex >> i;
                if(l.bad())
                {
                    cerr << "MT19937: Expected hex number. Got ";
                    if(l.eof())
                        cerr << "EOF" << endl;
                    else
                    {
                        cerr << l.get() << endl;
                    }

                    throw ParseError();
                }

                if(n==0)
                    rng.get_index() = i;
                else
                    rng.get_state()[n-1]=i;

            }

        }
\end{DoxyCode}


\subsubsection{Member Data Documentation}
\hypertarget{structMT19937_a5ae365b3da2b617913bc60e3ac98f2e4}{
\index{MT19937@{MT19937}!rng@{rng}}
\index{rng@{rng}!MT19937@{MT19937}}
\paragraph[{rng}]{\setlength{\rightskip}{0pt plus 5cm}CRandomMersenne {\bf MT19937::rng}}}
\label{structMT19937_a5ae365b3da2b617913bc60e3ac98f2e4}


Underlying RNG. 



Definition at line 39 of file mt19937.h.



Referenced by copy\_\-state(), operator()(), rand\_\-int(), read(), simple\_\-seed(), and write().



The documentation for this struct was generated from the following file:\begin{DoxyCompactItemize}
\item 
\hyperlink{mt19937_8h}{mt19937.h}\end{DoxyCompactItemize}
