37 template <
typename ScalarT>
42 seed(static_cast<ScalarT>(rand()))
45 if ((
seed == 0.0) || (
seed == 2147483647.0))
49 template <
typename ScalarT>
54 seed(static_cast<ScalarT>(rand()))
57 if ((
seed == 0.0) || (
seed == 2147483647.0))
61 template <
typename ScalarT>
63 Random(ScalarT a_, ScalarT b_,
int s) :
71 template <
typename ScalarT>
77 template <
typename ScalarT>
81 int ss = checkSeed(
"setSeed", s);
83 seed =
static_cast<ScalarT
>(s);
86 template <
typename ScalarT>
90 const ScalarT
A = 16807.0;
91 const ScalarT bigInt = 2147483647.0;
93 seed = std::fmod(A*seed, bigInt);
94 return (b-
a)*(seed/bigInt) +
a;
97 template <
typename ScalarT>
101 if ((s < 1) || (s > 2147483646)) {
102 std::cerr <<
"Error in Sacado::Random::" << s <<
"(): "
104 << s <<
" is not an integer between 1 and 2147483646."
105 << std::endl <<
"Using a seed of 1 instead." << std::endl;
112 #ifdef HAVE_SACADO_COMPLEX
114 template <
typename T>
122 template <
typename T>
124 Random(
const std::complex<T>&
a,
const std::complex<T>& b) :
125 rand_real(a.real(), b.real()),
126 rand_imag(a.imag(), b.imag())
130 template <
typename T>
132 Random(
const std::complex<T>&
a,
const std::complex<T>& b,
int s) :
133 rand_real(a.real(), b.real(), s),
134 rand_imag(a.imag(), b.imag(), s+1)
138 template <
typename T>
144 template <
typename T>
149 rand_imag.setSeed(s+1);
152 template <
typename T>
156 return std::complex<T>(rand_real.number(), rand_imag.number());
159 #endif // HAVE_SACADO_COMPLEX
ScalarT seed
Random number seed
int checkSeed(const std::string &func, int s)
ScalarT number()
Get random number.
void setSeed(int s)
Set seed to s.
const T func(int n, T *x)
A random number generator that generates random numbers uniformly distributed in the interval (a...