Jump to content

How does srand() work??


Guest KM

Recommended Posts

Hi,

I'm using that code to start the random function:

unsigned int dt = 0;


while ((GetAsyncKeyState (VK_RETURN) < 0)==false)


{


	dt = dt++;




}




srand(dt);

but it does not work,

and he produce allways the same numbers.

Any idea??

Link to comment
Share on other sites

Guest Stomski

srand sets a starting point for the random number generator. To ensure this is different every time you run your app, I would use the time.

eg... srand(time(void));

Then to get a random number between say, 0 and 9 inclusive, do:

int num = rand() % 10;

Link to comment
Share on other sites

I tried this to, but instead of time getsytem... (which return the seconds the system is on).

my compiler (evc 2002) doesn't know the time command and the time.h.

Any idea??

Link to comment
Share on other sites

I have tried this one too,

but it is always starts the same map.

What is strange that, the pc places the enemies randomly,

the map not.

I don't know what the bug is.

Maybe evc

:roll:

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.