I'm having a question in the program I made to represent the game cho-han bakuchi, this game has as a rule to roll two 6-sided dice in a cup before showing the dice if the bet is made in which the player speaks cho pairs) or han (odd) and then the data are shown and their values added.
In my program the game works except for the data roll, I'm using the time and srand function like this:
srand(time(NULL));
The problem is that once the program is compiled and run the time (clock time on my pc) is saved then whenever the data roll they will roll the same number because the srand is except in time X for example 14:32:43 let's say the data roll 4 and 4 would always like to know how I do to change this because no matter how many times they roll it will always be 4 and 4 I would like every given random data to always have what I do?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int die1;
int die2;
int sum;
int main()
{
int x, cred=100, y, apost;
srand(time(NULL));
die1=1+(rand()%6);
die2=1+(rand()%6);
sum=die1+die2;
while(cred!=0)
{
printf("faça a aposta:(digite -1 para sair)\n");
scanf("%d", &apost);
cred=cred-apost;
printf("\nescolha 1-cho(par) 2-han(impar):\n");
scanf("%d", &x);
printf("\njogador rolou %d+%d=%d\n", die1,die2,sum);
switch(x)
{
case 1:
if(sum%2==0)
{
printf("ganhou!\n");
cred=cred+(apost*2);
printf("seus creditos sao:%d\n",cred);
}
else
{
printf("perdeu!");
printf("seus creditos sao:%d\n",cred);
}
break;
case 2:
if(sum%2!=0)
{
printf("ganhou!\n");
cred=cred+(apost*2);
printf("seus creditos sao:%d\n",cred);
}
else
{
printf("perdeu!");
printf("seus creditos sao:%d\n",cred);
}
break;
}
}
return 0;
}