# # Challenge 2 Problem

 Laur T · August 25, 2015 Ok so I finished my program and I noticed that my three dice are rolling the same values and I wonder why?Here is my code:#include #include #include #include #include int main(){    int i,sum,sum2,diceRoll1,diceRoll2,diceRoll3;    char x;    diceRoll1=(rand()%6)+1;    diceRoll2=(rand()%6)+1;    diceRoll3=(rand()%6)+1;    sum=diceRoll1+diceRoll2+diceRoll3;    printf("%d %d %d\n",diceRoll1,diceRoll2,diceRoll3);    printf("The sum is : %d\n",sum);    printf("Is gonna be higher ,lower or the same (h,l,s): ");    scanf(" %c",&x);    switch(x){    case 'h':        diceRoll1=(rand()%6)+1;        diceRoll2=(rand()%6)+1;        diceRoll3=(rand()%6)+1;        sum2=diceRoll1+diceRoll2+diceRoll3;        printf("%d %d %d\n",diceRoll1,diceRoll2,diceRoll3);        printf("The sum is : %d\n",sum2);    if(sum2>sum)        printf("Good job the sum is higher!");    else        printf("The sum is not higher!");        break;    case 'l':        diceRoll1=(rand()%6)+1;        diceRoll2=(rand()%6)+1;        diceRoll3=(rand()%6)+1;        sum2=diceRoll1+diceRoll2+diceRoll3;        printf("%d %d %d\n",diceRoll1,diceRoll2,diceRoll3);        printf("The sum is : %d\n",sum2);    if(sum2

## Replies

 c student · August 25, 2015 rand uses a mathematical expression to calculate the numbers. using srand (seed) provides an alteration to this calculation. if your seed is static (the same every time), so will your rand value. if your seed is dynamic (constantly changing), so will your rand value.a typical srand is:#include srand (time (NULL));note that you will only need to call srand once. Laur T · August 26, 2015 Ok thanks for the info
• 1

## C

126,515 followers