22 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC_MINOR__ >= 5) || \
23 (defined(_MSC_VER) && _MSC_VER >= 1600)
24 # define HAVE_LAMBDA 1
27 # pragma warning (disable: 4239)
30 # define HAVE_LAMBDA 0
36 template<
typename RealType =
double>
class RandomNormal {
40 const RealType _mean, _sigma;
41 RandomNormal& operator=(
const RandomNormal&);
44 RealType mean = RealType(0), RealType sigma = RealType(1))
46 , _mean(mean), _sigma(sigma) {}
47 RealType operator()() {
return _n(_r, _mean, _sigma); }
50 template<
typename IntType =
unsigned>
class RandomInt {
53 RandomInt& operator=(
const RandomInt&);
57 IntType operator()(IntType x) {
return _r.Integer<IntType>(x); }
65 std::cout <<
"Illustrate calling STL routines with lambda expressions\n";
67 std::cout <<
"Illustrate calling STL routines without lambda expressions\n";
69 std::cout <<
"Using " << r.Name() <<
"\n"
70 <<
"with seed " << r.SeedString() <<
"\n\n";
72 std::vector<unsigned> c(10);
74 std::generate(c.begin(), c.end(),
75 [&r]()
throw() ->
unsigned {
return r(); });
78 (c.begin(), c.end(), r);
81 std::vector<double> b(10);
84 std::generate(b.begin(), b.end(),
85 [&r, &nf]()
throw() ->
double
86 {
return nf(r,0.0,2.0); });
88 std::generate(b.begin(), b.end(), RandomNormal<>(r,0.0,2.0));
91 std::vector<int> a(20);
94 std::generate(a.begin(), a.end(),
95 [&i]()
throw() ->
int {
return i++; });
96 std::random_shuffle(a.begin(), a.end(),
97 [&r](
unsigned long long n)
throw() ->
unsigned long long
98 {
return r.Integer<
unsigned long long>(n); });
100 for (
size_t i = 0; i < a.size(); ++i) a[i] =
int(i);
101 RandomInt<unsigned long long> shuffler(r);
102 std::random_shuffle(a.begin(), a.end(), shuffler);
Header for NormalDistribution.
Generate random integers, reals, and booleans.
Header for Random, RandomGenerator.