The setRandom function in the Eigen matrix library fills a given matrix with random numbers in the range [-1,1]. How can I extend this to generate numbers within any given range? I require floating point numbers and I am okay with pseudo-randomness.
I have tried doing the following:
B = LO + A.cast<double>().array()/(static_cast <double>(RAND_MAX)/(HI-LO));
Here A is the matrix in question and [LO,HI] is the range I am looking to fill it in. The problem is that the value of RAND_MAX for me is 2147483647 and this is messing up the entire calculation.
Any help is much appreciated.
m = LO+(ArrayXXd::Random(m,n)*0.5+0.5)*(HI-LO)
– Martins