Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | // This may look like C code, but it is really -*- C++ -*- |
2 | /* | |
3 | Copyright (C) 1988 Free Software Foundation | |
4 | written by Dirk Grunwald (grunwald@cs.uiuc.edu) | |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is distributed in the hope that it will be useful, | |
9 | but WITHOUT ANY WARRANTY. No author or distributor | |
10 | accepts responsibility to anyone for the consequences of using it | |
11 | or for whether it serves any particular purpose or works at all, | |
12 | unless he says so in writing. Refer to the GNU CC General Public | |
13 | License for full details. | |
14 | ||
15 | Everyone is granted permission to copy, modify and redistribute | |
16 | GNU CC, but only under the conditions described in the | |
17 | GNU CC General Public License. A copy of this license is | |
18 | supposed to have been given to you along with GNU CC so you | |
19 | can know your rights and responsibilities. It should be in a | |
20 | file named COPYING. Among other things, the copyright notice | |
21 | and this notice must be preserved on all copies. | |
22 | */ | |
23 | #ifndef _DiscreteUniform_h | |
24 | #ifdef __GNUG__ | |
25 | #pragma once | |
26 | #pragma interface | |
27 | #endif | |
28 | #define _DiscreteUniform_h 1 | |
29 | ||
30 | #include <Random.h> | |
31 | ||
32 | // | |
33 | // The interval [lo..hi) | |
34 | // | |
35 | ||
36 | class DiscreteUniform: public Random { | |
37 | long pLow; | |
38 | long pHigh; | |
39 | double delta; | |
40 | public: | |
41 | DiscreteUniform(long low, long high, RNG *gen); | |
42 | ||
43 | long low(); | |
44 | long low(long x); | |
45 | long high(); | |
46 | long high(long x); | |
47 | ||
48 | virtual double operator()(); | |
49 | }; | |
50 | ||
51 | #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES) | |
52 | ||
53 | inline DiscreteUniform::DiscreteUniform(long low, long high, RNG *gen) : (gen) | |
54 | { | |
55 | pLow = (low < high) ? low : high; | |
56 | pHigh = (low < high) ? high : low; | |
57 | delta = (pHigh - pLow) + 1; | |
58 | } | |
59 | ||
60 | inline long DiscreteUniform::low() { return pLow; } | |
61 | ||
62 | inline long DiscreteUniform::low(long x) { | |
63 | long tmp = pLow; | |
64 | pLow = x; | |
65 | delta = (pHigh - pLow) + 1; | |
66 | return tmp; | |
67 | } | |
68 | ||
69 | inline long DiscreteUniform::high() { return pHigh; } | |
70 | ||
71 | inline long DiscreteUniform::high(long x) { | |
72 | long tmp = pHigh; | |
73 | pHigh = x; | |
74 | delta = (pHigh - pLow) + 1; | |
75 | return tmp; | |
76 | } | |
77 | ||
78 | #endif | |
79 | #endif |