* normalized Gaussian probability
* distribution centered around @p a and
* with standard deviation @p sigma.
+ *
+ * This function is reentrant, i.e., it can safely be
+ * called from multiple threads at the same time. However, if
+ * so done, then there is no guarantee that each thread will
+ * get the same sequence of numbers every time. Rather, the
+ * produced sequence of random numbers will be apportioned to
+ * the different threads in non-deterministic ways. If this
+ * is a problem, for example for exactly reproducibility, then
+ * you need to use separate random number facilities for separate
+ * threads, rather than this global function. For example, the C++11
+ * standard offers such objects, as does BOOST.
*/
double
generate_normal_random_number (const double a,
DEAL_II_NAMESPACE_CLOSE
#endif
-
if (sigma == 0)
return a;
+ // we want to use rand(), but that function is not reentrant in a thread
+ // context. thus, use rand_r. this does not produce reproducible results
+ // between threads either, but at least it is reentrant. if you need
+ // an exactly reproducible sequence even in multithreaded contexts,
+ // then this is probably not the function to use.
#ifdef HAVE_RAND_R
static unsigned int seed = 0xabcd1234;
const double y = 1.0*rand_r(&seed)/RAND_MAX;