Code Monkey home page Code Monkey logo

Comments (3)

bab2min avatar bab2min commented on June 19, 2024 2

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 42.
If you want to get different results every run, you should pass the seed with different value like:

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:
You can change the minimum and maximum values of distribution with some arithmetic:

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].
But it looks ugly, so in the next update I'll add a function to set the min/max value more simply.

from eigenrand.

bab2min avatar bab2min commented on June 19, 2024

A new function overloading balanced and balancedLike for arbitrary range [a, b] was added at version 0.3.5.

from eigenrand.

andrewfowlie avatar andrewfowlie commented on June 19, 2024

@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.

from eigenrand.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.