Hello, I am in school programming a game using SDL.
It's a simple game where the player shoots at ships, which spawns randomly.
For this I call random function rand() each time in the game loop, then using the modulus operator to determine wether a new enemy will spawn.
The problem is, the random function frequently returns the same numbers, here's an example of output from the random function.
r: 41
r: 18467
r: 26435
r: 26435
r: 26438
r: 26438
r: 26438
r: 18083
r: 14284
r: 22658
r: 29693
r: 26441
r: 26441
r: 26441
r: 26441
r: 26441
I can't post the whole code, and I don't know which information which could be relevant, but here's basically what it is:
#include <time.h>
int main ( int argc, char** argv )
{
srand(time(0));
....
bool done = false;
while (!done)
{
int r=rand();
if(r%50==0){
//Spawn enemy
}
.....
So, what could the problem be? Help appreciated!