MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / randMatrix

Function randMatrix

src/utilities/data/Matrix.cpp:256–286  ·  view source on GitHub ↗

generates a Matrix of M*N points randomly drawn between and including a and b.

Source from the content-addressed store, hash-verified

254
255/// generates a Matrix of M*N points randomly drawn between and including a and b.
256Matrix 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
289double sum(const Matrix& matrix) {

Callers 1

TEST_FFunction · 0.85

Calls 1

equalFunction · 0.50

Tested by 1

TEST_FFunction · 0.68