Is there a diffrence between the GetTickCount() and rand() functions ? I read they both are Psuedorandom number generators , I would like to know if there is any diffrence between those two functions , I used rand() once and the output was the same each time the program run , would that change if i use GetTickCount instead ? thankyou very much :)
nico 0 Newbie Poster
Recommended Answers
Jump to Post— prog-bman 4The reason rand() generated the same numbers each time is that you have to seed the random number generator
#include <iostream> #include <ctime> using namespace std; int main() { int i; //seeds the number generator with time srand((unsigned int)time(NULL));//you only need to call this once in your …
Jump to Post— Emmitt310 0Adding on, GetTickCount() is also a way to seed the random number generator
srand( GetTickCount() );
All 5 Replies
prog-bman 4 Junior Poster
Emmitt310 0 Newbie Poster
nico 0 Newbie Poster
Chainsaw 12 Posting Pro in Training
nico 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.