37template <
typename ScalarT>
42 seed(static_cast<ScalarT>(rand()))
45 if ((
seed == 0.0) || (
seed == 2147483647.0))
49template <
typename ScalarT>
51Random(ScalarT a_, ScalarT b_) :
54 seed(static_cast<ScalarT>(rand()))
57 if ((seed == 0.0) || (seed == 2147483647.0))
61template <
typename ScalarT>
63Random(ScalarT a_, ScalarT b_,
int s) :
71template <
typename ScalarT>
77template <
typename ScalarT>
81 int ss = checkSeed(
"setSeed", s);
83 seed =
static_cast<ScalarT
>(s);
86template <
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;
97template <
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
124Random(
const std::complex<T>&
a,
const std::complex<T>& b) :
125 rand_real(
a.real(), b.real()),
126 rand_imag(
a.imag(), b.imag())
132Random(
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)
149 rand_imag.setSeed(s+1);
156 return std::complex<T>(rand_real.number(), rand_imag.number());
const T func(int n, T *x)
A random number generator that generates random numbers uniformly distributed in the interval (a,...
void setSeed(int s)
Set seed to s.
ScalarT seed
Random number seed
int checkSeed(const std::string &func, int s)
ScalarT number()
Get random number.