/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2004 by Christian Gagne and Marc Parizeau
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1K 7P4
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/RandomizerNR.hpp
 *  \brief  Definition of the class RandomizerNR.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.3 $
 *  $Date: 2004/04/25 23:12:21 $
 */

#ifndef Beagle_RandomizerNR_hpp
#define Beagle_RandomizerNR_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Randomizer.hpp"

#define Beagle_IA   16807
#define Beagle_IM   2147483647
#define Beagle_AM   (1.0/Beagle_IM)
#define Beagle_IQ   127773
#define Beagle_IR   2836
#define Beagle_NTAB 32
#define Beagle_NDIV (1+(Beagle_IM-1)/Beagle_NTAB)
#define Beagle_EPS  1.2e-7
#define Beagle_RNMX (1.0-Beagle_EPS)


namespace Beagle {


/*!
 *  \class RandomizerNR beagle/RandomizerNR.hpp "beagle/RandomizerNR.hpp"
 *  \brief Random number generator based on rand1 of "Numerical recipes in C".
 *  \ingroup ECF
 *  \ingroup Sys
 */
class RandomizerNR : public Randomizer {

public:

  //! RandomizerNR allocator type.
  typedef AllocatorT<RandomizerNR,Randomizer::Alloc>
          Alloc;
  //! RandomizerNR handle type.
  typedef PointerT<RandomizerNR,Randomizer::Handle>
          Handle;
  //! RandomizerNR bag type.
  typedef ContainerT<RandomizerNR,Randomizer::Bag>
          Bag;

           RandomizerNR();
  virtual ~RandomizerNR() { }

  virtual void          initRandomizer(unsigned long inState);
  virtual void          read(XMLNode::Handle& inNode);
  virtual unsigned long rollInteger(unsigned long inLower=0, unsigned long inUpper=ULONG_MAX);
  virtual double        rollUniform(double inLower=0.0, double inUpper=1.0);
  virtual void          write(XMLStreamer& ioStreamer) const;

protected:
  unsigned long mIV[Beagle_NTAB];  //!< Internal number generator values.
  unsigned long mIY;               //!< Internal number generator value.
  unsigned long mIDUM;             //!< Internal number generator value.

};

}

#endif // Beagle_RandomizerNR_hpp
