Version 3 Moved generator into a class. Is my new random number generation technique correct this time?
template<typename T = int>
class MyRandomGenerator
{
public:
MyRandomGenerator()
{
std::random_device rd;
gen = std::mt19937{rd()};
}
T getNumber(const T& From, const T& To)
{
std::uniform_int_distribution<T> dist(From, To);
return dist(gen);
}
private:
std::mt19937 gen;
};
And here my new position calculators:
auto calculate_x_position = [&]() ->sf::Uint32 {return RandGen.getNumber(0, W - 1); };
auto calculate_y_position = [&]() ->sf::Uint32 {return RandGen.getNumber(0, H - 1); };
Same pattern/problem as before:
Version 2 Creating ~3 maps per second of 10.000 stars per map. The outcome is still the same. Moreover, it gets even more clear that there is a pivot to the top of the maps. Example:
Original Question: i went into trying to draw a simple star map. For this i first calculate the x and y position for the stars. X and Y are within the range of width and height of the window.
This is my random number generating function:
template<typename T>
T getRandomNumberBetween(const T& Min, const T& Max)
{
static std::random_device rd;
static std::uniform_int_distribution<T> dist{Min, Max};
return dist(rd);
}
And i use it like this:
auto calculate_x_position = std::bind(inc::getRandomNumberBetween<sf::Uint32>, 0, Width-1);
auto calculate_y_position = std::bind(inc::getRandomNumberBetween<sf::Uint32>, 0, Height-1);
x = calculate_x_position(); //...
But as i draw my map over and over again it seems to me that there is a pivot to where most stars tend to be. E.g. the majority of stars are in the upper half of my window.
Example:
Am i using it wrong or having a wrong expectation here?... Because here it says:
This distribution produces random integers in a range [a,b] where each possible value has an equal likelihood of being produced.
Kind Regards