school/cs142/smcquay/cootie/dice.cc

26 lines
399 B
C++
Raw Normal View History

2016-04-06 20:45:34 -07:00
#include <cstdlib>
#include <ctime>
#include <sys/time.h>
#include <unistd.h>
#include "dice.h"
static int roll_count = 0;
void random_init() {
struct timeval tv;
gettimeofday(&tv, NULL);
pid_t pid = getpid();
srand(tv.tv_usec + pid);
}
int roll() {
roll_count++;
int compliment = rand() % 6;
return compliment + 1;
}
int get_roll_count() {
return roll_count;
}