I am using Visual Studio 2010 and C programming. I am trying to create a random integer value through the rand () method. Here is the code:
int main (void)
{
InitBuilding();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct
{
int type;
} BUILDING;
BUILDING g_aBld[200];
void InitBuilding(void)
{
srand((unsigned)time(NULL));
for(int cntBld = 0; cntBld < 200; cntBld++)
{
g_aBld[cntBld].type = (rand() % 3);
}
}
After debugging, I realized that 0 is continuously generated for each iteration of the loop. I used this exact code before in other programs and it worked fine. I have no idea why this will not work now. Thanks in advance for any answers.
source
share