Possible Duplicate:
Recommended way to initialize srand?
I am extracting frames from AVI. I want the user to choose wether he wants to get all frames from user given range or get all frames available or get user given number of random frames. First two functions work just fine. But with random frames I always get only one frame, not the given number of frames. So, here user sets the number of frames:
case AVIINF_BUTTON_GETRAND:
extractmode=-1;
GetDlgItemText(aviinfhwnd, AVIINF_EDIT_GETRAND, charfrQuantity, 20);
frQuantity = atoi(charfrQuantity);
ExtractAVIFrames(extractmode, frFrom, frTo, frQuantity);
EndDialog(aviinfhwnd, IDCANCEL);
break;
then in ExtractAVIFrames() after all inits and such I do this:
case -1://get x random frames
for (int i=1; i<=frQuantity; i++)
{
index= GetRandomInt(iNumFrames);
BYTE* pDIB = (BYTE*) AVIStreamGetFrame(pFrame, index);
CreateFromPackedDIBPointer(pDIB, index);
}
break;
which calls GetRandomInt()
int GetRandomInt(int randNumScale)
{
srand((unsigned)time(0));
int random_integer;
int range=randNumScale;
random_integer = (rand()%range)+1;
return random_integer;
}
so, this should call GetRandomInt() function frQuantity-times and I should have frQuantity BMPs, right? But I dont, I always get just one (random one). It seems that after each call the GetRandomInt returns the same number as in previous call. What's wrong? Thank you