generates a Matrix of M*N points randomly drawn between and including a and b.
| 254 | |
| 255 | /// generates a Matrix of M*N points randomly drawn between and including a and b. |
| 256 | Matrix randMatrix(double a, double b, unsigned M, unsigned N) { |
| 257 | Matrix result(M, N); |
| 258 | |
| 259 | // handle degenerate case |
| 260 | if (equal(a, b)) { |
| 261 | for (unsigned i = 0; i < M; ++i) { |
| 262 | for (unsigned j = 0; j < N; ++j) { |
| 263 | result(i, j) = a; |
| 264 | } |
| 265 | } |
| 266 | return result; |
| 267 | } |
| 268 | |
| 269 | // ETH@20100120. What library does this come from? The user should be able to seed the |
| 270 | // generator independently of this function. |
| 271 | // seed random number generator |
| 272 | thread_local std::minstd_rand generator(42u); |
| 273 | |
| 274 | // define distribution |
| 275 | boost::uniform_real<> dist(a, b); |
| 276 | |
| 277 | // create a generator |
| 278 | boost::variate_generator<std::minstd_rand&, boost::uniform_real<>> uniformGenerator(generator, dist); |
| 279 | |
| 280 | for (unsigned i = 0; i < M; ++i) { |
| 281 | for (unsigned j = 0; j < N; ++j) { |
| 282 | result(i, j) = uniformGenerator(); |
| 283 | } |
| 284 | } |
| 285 | return result; |
| 286 | } |
| 287 | |
| 288 | /// sum |
| 289 | double sum(const Matrix& matrix) { |