/// generates a Matrix of M*N points randomly drawn between and including a and b. Matrix randMatrix(double a, double b, unsigned M, unsigned N) { // ETH@20100120. What library does this come from? The user should be able to seed the // generator independently of this function. // seed random number generator static minstd_rand generator(42u); // define distribution uniform_real<> dist(a,b); // create a generator variate_generator<minstd_rand&, boost::uniform_real<> > uniformGenerator(generator, dist); // ETH@20120723 Started seeing this as DataFixture.Matrix_RandMatrix hangining on Windows 7, // with BoostPro installer. // handle degenerate case OptionalDouble singlePoint; if (equal(a,b)) { singlePoint = (a + b) / 2.0; } Matrix result(M, N); for (unsigned i = 0; i < M; ++i) { for (unsigned j = 0; j < N; ++j) { if (singlePoint) { result(i,j) = *singlePoint; } else { result(i,j) = uniformGenerator(); } } } return result; }
/// generates a Vector of N points randomly drawn between and including a and b. Vector randVector(double a, double b, unsigned N) { // seed random number generator static minstd_rand generator(42u); // define distribution uniform_real<> dist(a,b); // create a generator variate_generator<minstd_rand&, boost::uniform_real<> > uniformGenerator(generator, dist); Vector result(N); for (unsigned n = 0; n < N; ++n){ result(n) = uniformGenerator(); // draw from generator } return result; }