-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to generate different randomized matrices with min and max values? #24
Comments
Hi @NicoBrug MatrixXd m{rows,cols};
Rand::Vmt19937_64 urng{ 42 };
m = Rand::balancedLike(m, urng); It always returns the same result because the seed of random number generator is fixed as MatrixXd m{rows,cols};
auto seed = std::random_device{}(); // it requires #include <random>
Rand::Vmt19937_64 urng{ seed };
m = Rand::balancedLike(m, urng); For your second question: MatrixXd m{rows,cols};
double min_v = -2, max_v = 3;
Rand::Vmt19937_64 urng{ 42 };
m = ((Rand::balancedLike(m, urng).array() + 1) * (max_v - min_v) / 2 + min_v).matrix(); It will generate a matrix with uniform random reals in [-2, 3]. |
A new function overloading |
@bab2min I would find an example demonstrating the use of std::random_device helpful in the getting started section of the docs (https://bab2min.github.io/eigenrand/v0.5.0/en/getting_started.html). It's not the first time I've used C++11 style random number generation, but still somehow didn't find this obvious. |
I use the library to generate randomized arrays. I had 2 questions:
Why when I do
MatrixXd m{rows,cols}; Rand::Vmt19937_64 urng{ 42 }; Rand::balancedLike(m, urng); m = Rand::balancedLike(m, urng);
it always returns the same matrix with the same values.
And my other question: is it possible to choose min and max values to generate random numbers?
The text was updated successfully, but these errors were encountered: