PSCF v1.5.0
cpp/VecRandom.h
1#ifndef PSCF_VEC_RANDOM_CP_H
2#define PSCF_VEC_RANDOM_CP_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/backend/cpp/CPT.h>
12
13// Forward declarations
14namespace Util {
15 class Random;
16 template <typename T> class Array;
17}
18namespace Pscf {
19
20 template <typename T> class VecRandom;
21
22 template <typename T>
23 void linkVecRandom(VecRandom<T>& vr, Random & sr);
24
25 template <typename T>
26 void seedVecRandom(VecRandom<T>& vr, long seed);
27}
28
29namespace Pscf {
30
31 using namespace Util;
32
42 template <>
44 {
45
46 public:
47
51 VecRandom();
52
58 VecRandom(Util::Random& random);
59
63 ~VecRandom();
64
65 // Prohibit copying and assignment
66 VecRandom(VecRandom<CPT> const &) = delete;
67 VecRandom<CPT> operator = (VecRandom<CPT> const &) = delete;
68
74 void associate(Util::Random& random);
75
81 void uniform(Util::Array<double>& data);
82
90 void uniform(Util::Array<double>& data, double min, double max);
91
99 void normal(Util::Array<double>& data, double stddev, double mean = 0.0);
100
101 private:
102
104 Util::Random* randomPtr_;
105
106 };
107
108 // Related free functions. Used for initialization.
109
122 template <>
123 void linkVecRandom(VecRandom<CPT>& vr, Random & sr);
124
136 template <>
137 void seedVecRandom(VecRandom<CPT>& vr, long seed);
138
139
140} // namespace Pscf
141#endif
Backend identifier class for the C++ serial CPU backend.
Definition CPT.h:32
VecRandom()
Default constructor.
Definition VecRandom.cpp:13
void associate(Util::Random &random)
Create an association with a Util::Random scalar RNG.
Definition VecRandom.cpp:33
void normal(Util::Array< double > &data, double stddev, double mean=0.0)
Generate normal-distributed random doubles.
Definition VecRandom.cpp:66
void uniform(Util::Array< double > &data)
Generate uniform random doubles in (0, 1].
Definition VecRandom.cpp:39
Array container class template.
Definition Array.h:41
Random number generator.
Definition Random.h:47
PSCF package top-level namespace.
Utility classes for scientific computation.