Sign in to follow this  
raptorstrike

Rand() question

Recommended Posts

That's correct.

srand() initialises your random number generator to a specific seed. So subsequent calls to rand() will always return the same sequence of numbers when the same seed was used.

You can feed the current time or some other really random value to srand() to have a unique chain of random numbers.

Share this post


Link to post
Share on other sites
When in doubt, read the specifications of the function in question.
(or as we used to say, RTFM :).)

A good place to look is MSDN:

rand()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_rand.asp

srand()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_srand.asp

[EDIT]
I noticed you also seem to be having problems with the % (modulus) operator.

What it does is return the remainder of a division between two numbers.

EG: 10 % 10 gives zero, as ten divides ten evenly.
Wheras 10 % 5 yields 5.
[/EDIT]
- Jacob

Share this post


Link to post
Share on other sites
I think the proper funcion to get the time would be GetTickCount.

edit: It doesn't get the time, but rather the number of milliseconds elapsed since the program began execution. This will never (very seldom) be the same, even on the same macine with no other tasks running.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this