blitz Version 1.0.2
Loading...
Searching...
No Matches
discrete-uniform.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 * random/discrete-uniform.h Discrete uniform IRNG wrapper class
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions: blitz-devel@lists.sourceforge.net
25 * Bugs: blitz-support@lists.sourceforge.net
26 *
27 * For more information, please see the Blitz++ Home Page:
28 * https://sourceforge.net/projects/blitz/
29 *
30 ***************************************************************************/
31
32#ifndef BZ_RANDOM_DISCRETE_UNIFORM_H
33#define BZ_RANDOM_DISCRETE_UNIFORM_H
34
35#include <random/default.h>
36
37namespace ranlib {
38
39template<typename T = unsigned int, typename IRNG = defaultIRNG,
40 typename stateTag = defaultState>
41class DiscreteUniform : public IRNGWrapper<IRNG,stateTag>
42{
43public:
44 typedef T T_numtype;
45
47 {
48 BZPRECONDITION(n < 4294967295U);
49 n_ = n;
50 }
51
52 DiscreteUniform(T n, unsigned int i) :
53 IRNGWrapper<IRNG,stateTag>::IRNGWrapper(i)
54 {
55 BZPRECONDITION(n < 4294967295U);
56 n_ = n;
57 }
58
60 {
61 return this->irng_.random() % n_;
62 }
63
64private:
65 T n_;
66};
67
68}
69
70#endif // BZ_RANDOM_DISCRETE_UNIFORM_H
Definition: discrete-uniform.h:42
DiscreteUniform(T n)
Definition: discrete-uniform.h:46
T T_numtype
Definition: discrete-uniform.h:44
T n_
Definition: discrete-uniform.h:65
DiscreteUniform(T n, unsigned int i)
Definition: discrete-uniform.h:52
T random()
Definition: discrete-uniform.h:59
Definition: default.h:68
Definition: beta.h:50
sharedState defaultState
Definition: default.h:55
MersenneTwister defaultIRNG
Definition: default.h:120