1 | /*************************************************************************** |
---|
2 | * blitz/randref.h Random number generators, expression templates |
---|
3 | * wrapper |
---|
4 | * |
---|
5 | * $Id: randref.h,v 1.5 2003/12/11 03:44:22 julianc Exp $ |
---|
6 | * |
---|
7 | * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * Suggestions: blitz-dev@oonumerics.org |
---|
20 | * Bugs: blitz-bugs@oonumerics.org |
---|
21 | * |
---|
22 | * For more information, please see the Blitz++ Home Page: |
---|
23 | * http://oonumerics.org/blitz/ |
---|
24 | * |
---|
25 | ***************************************************************************/ |
---|
26 | |
---|
27 | #ifndef BZ_RANDREF_H |
---|
28 | #define BZ_RANDREF_H |
---|
29 | |
---|
30 | #ifndef BZ_RANDOM_H |
---|
31 | #error <blitz/randref.h> must be included via <blitz/random.h> |
---|
32 | #endif // BZ_RANDOM_H |
---|
33 | |
---|
34 | BZ_NAMESPACE(blitz) |
---|
35 | |
---|
36 | template<typename P_distribution> |
---|
37 | class _bz_VecExprRandom { |
---|
38 | |
---|
39 | public: |
---|
40 | typedef _bz_typename Random<P_distribution>::T_numtype T_numtype; |
---|
41 | |
---|
42 | _bz_VecExprRandom(Random<P_distribution>& random) |
---|
43 | : random_(random) |
---|
44 | { } |
---|
45 | |
---|
46 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR |
---|
47 | _bz_VecExprRandom(_bz_VecExprRandom<P_distribution>& x) |
---|
48 | : random_(x.random_) |
---|
49 | { } |
---|
50 | #endif |
---|
51 | |
---|
52 | T_numtype operator[](unsigned) const |
---|
53 | { return random_.random(); } |
---|
54 | |
---|
55 | T_numtype operator()(unsigned) const |
---|
56 | { return random_.random(); } |
---|
57 | |
---|
58 | unsigned length(unsigned recommendedLength) const |
---|
59 | { return recommendedLength; } |
---|
60 | |
---|
61 | unsigned _bz_suggestLength() const |
---|
62 | { return 0; } |
---|
63 | |
---|
64 | bool _bz_hasFastAccess() const |
---|
65 | { return 1; } |
---|
66 | |
---|
67 | T_numtype _bz_fastAccess(unsigned) const |
---|
68 | { return random_.random(); } |
---|
69 | |
---|
70 | private: |
---|
71 | _bz_VecExprRandom() : random_( Random<P_distribution>() ) { } |
---|
72 | |
---|
73 | Random<P_distribution>& random_; |
---|
74 | }; |
---|
75 | |
---|
76 | BZ_NAMESPACE_END |
---|
77 | |
---|
78 | #endif // BZ_RANDREF_H |
---|
79 | |
---|