/* DICE ROLLER*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rnd(int range);
void seedrnd(void);
int main()
{
char ch;
int x,number,sides;
char temp[3];
printf("# of sides: ");
gets(temp);
sides=atoi(temp);
printf("# of dice: ");
gets(temp);
number=atoi(temp);
seedrnd();
for(x=0;x<number;x++)
printf("%d\t",rnd(sides));
return(0);
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r+1);
}
/*seed the random number*/
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
No comments:
Post a Comment