I have this function that dices a lot the function
below and it does it all really fast and all the
numbers are almost always the same. Is there a way I
can perform the bottom function without producing the
same results for each attribute.
Code:
short int dice(int size)
{
short int rc;
/* srand Must be different for different random numbers,
it seeds the function rand */
srand((17237210 * time(NULL)));
rc = (rand() % (size - 1 + 1) + 1);
return rc;
}
bool dice_attributes(struct players *ch)
{
short int roll[4] = { 0, 0, 0, 0};
roll[0] = dice(6);
roll[1] = dice(6);
roll[2] = dice(6);
roll[3] = dice(6);
ch->str += (roll[0] + roll[1] + roll[2] + roll[3]);
roll[0] = dice(6);
roll[1] = dice(6);
roll[2] = dice(6);
roll[3] = dice(6);
ch->dex += (roll[0] + roll[1] + roll[2] + roll[3]);
roll[0] = dice(6);
roll[1] = dice(6);
roll[2] = dice(6);
roll[3] = dice(6);
ch->con += (roll[0] + roll[1] + roll[2] + roll[3]);
roll[0] = dice(6);
roll[1] = dice(6);
roll[2] = dice(6);
roll[3] = dice(6);
ch->in += (roll[0] + roll[1] + roll[2] + roll[3]);
roll[0] = dice(6);
roll[1] = dice(6);
roll[2] = dice(6);
roll[3] = dice(6);
ch->wis += (roll[0] + roll[1] + roll[2] + roll[3]);
roll[0] = dice(6);
roll[1] = dice(6);
roll[2] = dice(6);
roll[3] = dice(6);
ch->cha += (roll[0] + roll[1] + roll[2] + roll[3]);
}