In my c++ code I have a problem. My random drawBlock function which should return xRandom and yRandom is not so random.
void Game::drawBlock()
{
int xRandom, yRandom;
std::cout<<time(NULL) << std::endl;
xRandom = (rand () % 620) + 1;
yRandom = (rand () % 440) + 1;
std::cout << "x: " << xRandom << std::endl;
std::cout << "y: " << yRandom;
mBlock.setSize(sf::Vector2f(20,20));
mBlock.setPosition(xRandom,yRandom);
mBlock.setFillColor(sf::Color::Red);
}
so what basically happens is that the first random number, in this case xRandom isn't really random. When I run the program everything seems fine xRandom gets a random number and yRandom gets a random number. But when I restart the program my xRandom number is almost the same. while my yRandom number changes completely. so for example when I start my code: xRandom = 33 yRandom = 381 when I than re-run my code xRandom = 41 and after re-running it for 10 times is looks something like this: 55,66,84,101,125,140,180,201,234,251 Something strange is that the new xRandom is always more than the last one.
Here is the code were I call srand:
#include <SFML/Graphics.hpp>
#include "Game.h"
int main()
{
srand(time(0));
Game game;
game.run();
return 0;
}