Sign in to follow this  

GetTickCount Function

This topic is 4103 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

That's the second of this kind of threads.
I don't think you want to reverse the time (time travel is not possible in C++), what exactly is the effect you want to archieve?

If you want your program to go through the same set of random numbers at some point again, then you have two options:
1) Don't use any time functions to seed your random generator, use a static variable.
2) Save the current time to a variable, seed your generator with the variable and at the point you want to see the exact same row of random numbers again, reseed it with the same number.

Trying to reverse the windows uptime is not what you want, really.

Share this post


Link to post
Share on other sites
Yeah, why do you want to mess with the system clock? I thought we covered this in your other thread :)

As suggested above, maybe you could clarify what your purpose is. If your intention is to generate a reproducable series of pseudo-random numbers by using the same seed, and you think that resetting the system clock is the only (or even an appropriate) way to do this, then you don't yet understand the principles behind srand() and rand(), plain and simple.

Anyway, don't make us guess - tell us what you really want to do so we can recommend an appropriate solution.

Share this post


Link to post
Share on other sites
I wanted to create a program to generate random numbers. By using GetTickCount, its bases on seconds. So if my program was show the random generated numbers. I also want to beable to also guess what the seeded number is.

Basicly I want to beable to know, how to find out how or how to adjust it.

Am woundering now, am I the only person thats asked these weird questions?

Share this post


Link to post
Share on other sites
GetTickCount() gives you the uptime in milliseconds, not seconds.

I am still not sure what you want to do.
Do you want to have a game where you the user has to guess the seeding number by watching the random numbers? This is not possible, no human would manage that.

But if all you want is to let your program know what the seeding number is, then you could use the following:

long seed = GetTickCount();
srand(seed);
.....

This way you will know what your seeding number was and if you want to rebuild the same random number sequence again, all you need to so is
...srand(seed);...
again. All the random numbers generated would match the first sequence of numbers you had after seeding for the first time.

Share this post


Link to post
Share on other sites
Why don't you access a file that holds the seeded number. If the file doesn't exist (program has never been run) then you would use GetTickCount as your seed, and save the value of GetTickCount into a file. Then, later on, you access the file again, at this point, it WOULD exist, and you can use that number instead. Here's an example:

FIRST RUN (DAY 1)
1. (CurrentTime is 9854981)
2. Open File.txt to see if there is a time value in it.
3. There is no time in File.txt
4. Because there is no time in File.txt, use GetTickCount for the seed
5. (Seed = GetTickCount)
6. (Save Seed into File.txt) (File.txt now contains the value 9854981)
7. (Execute random value with the seed)


SECOND RUN (DAY 2)
1. (CurrentTime is 1965191321) (these are made up numbers btw)
2. Open File.txt to see if there is a time value in it.
3. There IS a time value in it.
4. The time value is: 9854981
5. (Seed = 9854981)
6. (Execute random value with the seed)

That's SORT of like going back into time :)

Share this post


Link to post
Share on other sites

This topic is 4103 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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