I have a function which is supposed to generate a random number depending of the size of a vector. But each time I execute my program, the patterns are the same 1->1->1->0
but my array can contains 0-4
value.
std::pair<int, int> Maze::getDirection(int x, int y)
{
std::vector<std::pair<int, int>> location;
if (m_maze[x + 1][y] == '*')
location.emplace_back(std::make_pair(x + 1, y));
if (m_maze[x - 1][y] == '*')
location.emplace_back(std::make_pair(x - 1, y));
if (m_maze[x][y + 1] == '*')
location.emplace_back(std::make_pair(x, y + 1));
if (m_maze[x][y - 1] == '*')
location.emplace_back(std::make_pair(x, y - 1));
std::cout << "Random number: " << std::rand() % location.size() << "\n" << "Size of vector: " << location.size() << std::endl;
std::srand(std::time(nullptr));
return location.at(std::rand() % location.size());
}