i know what srand does and how to type it but instead of typing NULL can you use like a 1 so it creates a number every milisecond?
typing it as follows:
srand(time(1));
or something like it.
i know what srand does and how to type it but instead of typing NULL can you use like a 1 so it creates a number every milisecond?
typing it as follows:
srand(time(1));
or something like it.
rand() creates a sequence of pseudo random numbers
srand() just defines the start point for the sequence
The second set of 3 rands will always be the same as the first setCode:srand(1); a=rand(); b=rand(); c=rand(); srand(1); a=rand(); b=rand(); c=rand();
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
try
and include windows.hCode:srand(GetTickCount());
thats only on win32 machines
Good Help Source all round
Good help for win programmers
you will probably find something in here
this thing also helps
if you have never tried any of the above then maybe you should, they help alot
what does srand(GetTickCount()); do?
It means you should at least look up those two functions in the relevant manual pages.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
As Salem has stated, if you seed your random number generator with a constant, you will get the same pseudorandom sequence each time. Initiallising it with GetTickCount() will ensure that it is different each time.
GetTickCount() on a WIndows machine returns the number of milliseconds since the system was last started.
*** EDIT ***
Salems next post happened while Iwas typing, he is right of course, you do need to learn how to look up basic functions like these in the help, MSDN or other online resources.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Here’s what you have to do:
1. Make random numbers.
2. Get & compare elapsed time.
3. Make a loop.
Your program requires the use of time for two different purposes:
1. To seed the random number generator. Ideally, you'd like to seed the random number generator with a random number!
2. To keep track of elapsed time, so you can generate a new random number every millisecond.
Whenever you do something over-and-over, you need a loop!…so it creates a number every milisecond?
For time-delay you have a choice:
1. You can run a “tight” loop re-checking the elapsed time at as fast as the CPU can go. (This makes your program a CPU hog.)
2. Pause or Sleep() for a fixed time during the loop. All of the methods of pausing are system-specific. There is no way to do this using pure ANSI/ISO standard C++.
You can use time() from the <ctime> header, or if you’re running Windows, use GetTickCount from the <windows> header. There is a problem with time() on Windows systems-- It doesn’t get updated every single millisecond… it "jumps"… Oh, I forget… every 40ms or so.
wow you sure do know how to confuse i kid.
i fixed my program through a different way. thank you for your posts and maybe ill be able to learn more outta it next time.
No one died when Clinton lied.
Compiler: Borland C++ Builder
OS: Windows XP