blitz
Version 0.9
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
blitz
rand-dunif.h
Go to the documentation of this file.
1
/***************************************************************************
2
* blitz/rand-dunif.h Discrete uniform generator
3
*
4
* $Id: rand-dunif.h,v 1.4 2003/12/11 03:44:22 julianc Exp $
5
*
6
* Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
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-dev@oonumerics.org
19
* Bugs: blitz-bugs@oonumerics.org
20
*
21
* For more information, please see the Blitz++ Home Page:
22
* http://oonumerics.org/blitz/
23
*
24
***************************************************************************/
25
26
#ifndef BZ_RAND_DUNIF_H
27
#define BZ_RAND_DUNIF_H
28
29
#ifndef BZ_RANDOM_H
30
#include <
blitz/random.h
>
31
#endif
32
33
#ifndef BZ_RAND_UNIFORM_H
34
#include <
blitz/rand-uniform.h
>
35
#endif
36
37
#include <math.h>
38
39
BZ_NAMESPACE
(blitz)
40
41
template<typename P_uniform
BZ_TEMPLATE_DEFAULT
(
Uniform
)>
42
class
DiscreteUniform
{
43
44
public
:
45
typedef
int
T_numtype
;
46
typedef
P_uniform
T_uniform
;
47
48
DiscreteUniform(
int
low,
int
high,
double
=0)
49
: low_(low), range_(high-low+1)
50
{
51
}
52
53
void
randomize()
54
{
55
uniform_.randomize();
56
}
57
58
int
random()
59
{
60
return
int(uniform_.random() * range_ + low_);
61
}
62
63
private
:
64
int
low_,
range_
;
65
T_uniform
uniform_
;
66
};
67
68
BZ_NAMESPACE_END
69
70
#endif // BZ_RAND_DUNIF_H
71
Generated on Fri Jun 15 2012 12:01:11 for blitz by
1.8.1.1