15 template <
typename ScalarT>
20 seed(static_cast<ScalarT>(rand()))
23 if ((
seed == 0.0) || (
seed == 2147483647.0))
27 template <
typename ScalarT>
32 seed(static_cast<ScalarT>(rand()))
35 if ((
seed == 0.0) || (
seed == 2147483647.0))
39 template <
typename ScalarT>
41 Random(ScalarT a_, ScalarT b_,
int s) :
49 template <
typename ScalarT>
55 template <
typename ScalarT>
59 int ss = checkSeed(
"setSeed", s);
61 seed =
static_cast<ScalarT
>(s);
64 template <
typename ScalarT>
68 const ScalarT
A = 16807.0;
69 const ScalarT bigInt = 2147483647.0;
71 seed = std::fmod(A*seed, bigInt);
72 return (b-
a)*(seed/bigInt) +
a;
75 template <
typename ScalarT>
79 if ((s < 1) || (s > 2147483646)) {
80 std::cerr <<
"Error in Sacado::Random::" << s <<
"(): "
82 << s <<
" is not an integer between 1 and 2147483646."
83 << std::endl <<
"Using a seed of 1 instead." << std::endl;
90 #ifdef HAVE_SACADO_COMPLEX
100 template <
typename T>
102 Random(
const std::complex<T>&
a,
const std::complex<T>& b) :
103 rand_real(a.real(), b.real()),
104 rand_imag(a.imag(), b.imag())
108 template <
typename T>
110 Random(
const std::complex<T>&
a,
const std::complex<T>& b,
int s) :
111 rand_real(a.real(), b.real(), s),
112 rand_imag(a.imag(), b.imag(), s+1)
116 template <
typename T>
122 template <
typename T>
127 rand_imag.setSeed(s+1);
130 template <
typename T>
134 return std::complex<T>(rand_real.number(), rand_imag.number());
137 #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...