now i'm doing a mastermind homework..
my problem is how can i randomize once only when the program is running..
Code:
nine()
{
int f,s,t,fo,fi,si,sev,ei,nin,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,r,p;
f=(rand()%10);
s=(rand()%10);
t=(rand()%10);
fo=(rand()%10);
fi=(rand()%10);
si=(rand()%10);
sev=(rand()%10);
ei=(rand()%10);
nin=(rand()%10);
r=0;
p=0;

printf("%d%d%d%d%d%d%d%d%d",f,s,t,fo,fi,si,sev,ei,nin);
printf("Please input your guess(In One Digit)");
printf("\nFirst\n");
scanf("%d",&first);
printf("Second\n");
scanf("%d",&second);
printf("Third\n");
scanf("%d",&third);
printf("Fourth\n");
scanf("%d",&fourth);
printf("Fifth\n");
scanf("%d",&fifth);
nine()
{
int f,s,t,fo,fi,si,sev,ei,nin,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,r,p;
f=(rand()%10);
s=(rand()%10);
t=(rand()%10);
fo=(rand()%10);
fi=(rand()%10);
si=(rand()%10);
sev=(rand()%10);
ei=(rand()%10);
nin=(rand()%10);
r=0;
p=0;

printf("%d%d%d%d%d%d%d%d%d",f,s,t,fo,fi,si,sev,ei,nin);
printf("Please input your guess(In One Digit)");
printf("\nFirst\n");
scanf("%d",&first);
printf("Second\n");
scanf("%d",&second);
printf("Third\n");
scanf("%d",&third);
printf("Fourth\n");
scanf("%d",&fourth);
printf("Fifth\n");
scanf("%d",&fifth);
if(third==t)
r=r+1;
else if(third==f||third==s||third==fo||third==fi||third==si||third==sev||third==ei||third==nin)
p=p+1;
else if(!(third==t||third==f||third==s||third==fo||third==fi||third==si||third==sev||third==ei||thir
d==nin))
{}

if(fourth==fo)
r=r+1;
else if(fourth==f||fourth==s||fourth==t||fourth==fi||fourth==si||fourth==sev||fourth==ei||fourth==ni
n)
p=p+1;
else if(!(fourth==f||fourth==s||fourth==t||fourth==fi||fourth==si||fourth==sev||fourth==ei||fourth==
nin))
{}

if(fifth==fi)
r=r+1;
else if(fifth==f||fifth==s||fifth==t||fifth==fo||fifth==si||fifth==sev||fifth==ei||fifth==nin)
p=p+1;
else if(!(fifth==fi||fifth==f||fifth==s||fifth==t||fifth==fo||fifth==si||fifth==sev||fifth==ei||fift
h==nin))
{}
if(sixth==si)
r=r+1;
else if(sixth==f||sixth==s||sixth==t||sixth==fo||sixth==fi||sixth==sev||sixth==ei||sixth==nin)
p=p+1;
else if(!(sixth==si||sixth==f||sixth==s||sixth==t||sixth==fo||sixth==fi||sixth==sev||sixth==ei||sixt
h==nin))
{}
if(seventh==sev)
r=r+1;
else if(seventh==f||seventh==s||seventh==t||seventh==fo||seventh==fi||seventh==si||seventh==ei||seve
nth==nin)
p=p+1;
else if(!(seventh==f||seventh==s||seventh==t||seventh==fo||seventh==fi||seventh==si||seventh==ei||se
venth==nin||seventh==sev))
{}
if(eighth==ei)
r=r+1;
else if(eighth==f||eighth==s||eighth==t||eighth==fo||eighth==fi||eighth==si||eighth==sev||eighth==ni
n)
p=p+1;
else if(!(eighth==f||eighth==s||eighth==t||eighth==fo||eighth==fi||eighth==si||eighth==sev||eighth==
nin||eighth==ei))
{}
if(ninth==nin)
r=r+1;
else if(ninth==f||ninth==s||ninth==t||ninth==fo||ninth==fi||ninth==si||ninth==sev||ninth==ei)
p=p+1;
else if(!(ninth=ei||ninth==f||ninth==s||ninth==t||ninth==fo||ninth==fi||ninth==si||ninth==sev||ninth
==nin))
{}

if(r==9)
{printf("Congratulations,You Guess Right,You Are The Mastermind!!");
return 0;
}

printf("\n%d Right,%d Place Wrong\n",r,p);
return nine();
}
sorry if the code too long. ,anyone can help?