| [658] | 1 | /*************************************************************************** | 
|---|
|  | 2 | * blitz/rand-dunif.h    Discrete uniform generator | 
|---|
|  | 3 | * | 
|---|
|  | 4 | * $Id: rand-dunif.h,v 1.1.1.1 1999-11-26 16:37:04 ansari Exp $ | 
|---|
|  | 5 | * | 
|---|
|  | 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | 
|---|
|  | 7 | * | 
|---|
|  | 8 | * This program is free software; you can redistribute it and/or | 
|---|
|  | 9 | * modify it under the terms of the GNU General Public License | 
|---|
|  | 10 | * as published by the Free Software Foundation; either version 2 | 
|---|
|  | 11 | * of the License, or (at your option) any later version. | 
|---|
|  | 12 | * | 
|---|
|  | 13 | * This program is distributed in the hope that it will be useful, | 
|---|
|  | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 16 | * GNU General Public License for more details. | 
|---|
|  | 17 | * | 
|---|
|  | 18 | * Suggestions:          blitz-suggest@cybervision.com | 
|---|
|  | 19 | * Bugs:                 blitz-bugs@cybervision.com | 
|---|
|  | 20 | * | 
|---|
|  | 21 | * For more information, please see the Blitz++ Home Page: | 
|---|
|  | 22 | *    http://seurat.uwaterloo.ca/blitz/ | 
|---|
|  | 23 | * | 
|---|
|  | 24 | *************************************************************************** | 
|---|
|  | 25 | * $Log: not supported by cvs2svn $ | 
|---|
|  | 26 | * Revision 1.1.1.1  1999/04/09  17:59:02  ansari | 
|---|
|  | 27 | * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99 | 
|---|
|  | 28 | * | 
|---|
|  | 29 | * Revision 1.2  1998/03/14 00:04:47  tveldhui | 
|---|
|  | 30 | * 0.2-alpha-05 | 
|---|
|  | 31 | * | 
|---|
|  | 32 | * Revision 1.1  1997/07/16 14:51:20  tveldhui | 
|---|
|  | 33 | * Update: Alpha release 0.2 (Arrays) | 
|---|
|  | 34 | * | 
|---|
|  | 35 | */ | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #ifndef BZ_RAND_DUNIF_H | 
|---|
|  | 38 | #define BZ_RAND_DUNIF_H | 
|---|
|  | 39 |  | 
|---|
|  | 40 | #ifndef BZ_RANDOM_H | 
|---|
|  | 41 | #include <blitz/random.h> | 
|---|
|  | 42 | #endif | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #ifndef BZ_RAND_UNIFORM_H | 
|---|
|  | 45 | #include <blitz/rand-uniform.h> | 
|---|
|  | 46 | #endif | 
|---|
|  | 47 |  | 
|---|
|  | 48 | #include <math.h> | 
|---|
|  | 49 |  | 
|---|
|  | 50 | BZ_NAMESPACE(blitz) | 
|---|
|  | 51 |  | 
|---|
|  | 52 | template<class P_uniform BZ_TEMPLATE_DEFAULT(Uniform)> | 
|---|
|  | 53 | class DiscreteUniform { | 
|---|
|  | 54 |  | 
|---|
|  | 55 | public: | 
|---|
|  | 56 | typedef int T_numtype; | 
|---|
|  | 57 | typedef P_uniform T_uniform; | 
|---|
|  | 58 |  | 
|---|
|  | 59 | DiscreteUniform(int low, int high, double=0) | 
|---|
|  | 60 | : low_(low), range_(high-low+1) | 
|---|
|  | 61 | { | 
|---|
|  | 62 | } | 
|---|
|  | 63 |  | 
|---|
|  | 64 | void randomize() | 
|---|
|  | 65 | { | 
|---|
|  | 66 | uniform_.randomize(); | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | int random() | 
|---|
|  | 70 | { | 
|---|
|  | 71 | return int(uniform_.random() * range_ + low_); | 
|---|
|  | 72 | } | 
|---|
|  | 73 |  | 
|---|
|  | 74 | private: | 
|---|
|  | 75 | int low_, range_; | 
|---|
|  | 76 | T_uniform uniform_; | 
|---|
|  | 77 | }; | 
|---|
|  | 78 |  | 
|---|
|  | 79 | BZ_NAMESPACE_END | 
|---|
|  | 80 |  | 
|---|
|  | 81 | #endif // BZ_RAND_DUNIF_H | 
|---|
|  | 82 |  | 
|---|