blitz/rand-dunif.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  * blitz/rand-dunif.h    Discrete uniform generator
00003  *
00004  * $Id: rand-dunif.h,v 1.4 2003/12/11 03:44:22 julianc Exp $
00005  *
00006  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * Suggestions:          blitz-dev@oonumerics.org
00019  * Bugs:                 blitz-bugs@oonumerics.org
00020  *
00021  * For more information, please see the Blitz++ Home Page:
00022  *    http://oonumerics.org/blitz/
00023  *
00024  ***************************************************************************/
00025 
00026 #ifndef BZ_RAND_DUNIF_H
00027 #define BZ_RAND_DUNIF_H
00028 
00029 #ifndef BZ_RANDOM_H
00030  #include <blitz/random.h>
00031 #endif
00032 
00033 #ifndef BZ_RAND_UNIFORM_H
00034  #include <blitz/rand-uniform.h>
00035 #endif
00036 
00037 #include <math.h>
00038 
00039 BZ_NAMESPACE(blitz)
00040 
00041 template<typename P_uniform BZ_TEMPLATE_DEFAULT(Uniform)>
00042 class DiscreteUniform {
00043 
00044 public:
00045     typedef int T_numtype;
00046     typedef P_uniform T_uniform;
00047 
00048     DiscreteUniform(int low, int high, double=0)
00049         : low_(low), range_(high-low+1)
00050     { 
00051     }
00052 
00053     void randomize() 
00054     { 
00055         uniform_.randomize();
00056     }
00057   
00058     int random()
00059     { 
00060         return int(uniform_.random() * range_ + low_);
00061     } 
00062 
00063 private:
00064     int low_, range_;
00065     T_uniform uniform_;
00066 };
00067 
00068 BZ_NAMESPACE_END
00069 
00070 #endif // BZ_RAND_DUNIF_H
00071 

Generated on Tue Dec 4 07:47:57 2007 for blitz by  doxygen 1.4.7