00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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