I am trying to generate random numbers of shape {10} and range between -0.5 and 0.5
#include <iostream>
#include <xtensor/xio.hpp>
#include <xtensor/xrandom.hpp>
int main() {
xt::xarray<double> a = xt::random::randn<double>({10}, -0.5, 0.5);
std::cout << a;
return 0;
}
but it's returning an array
{-0.432735, -0.573191, -0.269675, -1.435692, -0.418144, -0.607127,
-0.350702, -0.913972, -0.494892, 0.027733}
where -0.573191 is smaller and -1.435692 is bigger than range
According to the documentation for
randn
:The function draws numbers from
std::normal_distribution
and you've set the mean value to be-0.5
and the standard deviation to be0.5
. These are not lower and upper bounds.You may want to use the
rand
function instead:This draws numbers from
std::uniform_real_distribution
- so, it's not the same thing, but it has a lower and an upper bound.