double randomReal(double low, double high) { double d, s; initRandomSeed(); d = rand() / ((double) RAND_MAX + 1); s = d * (high - low); return low + s; }
int randomInteger(int low, int high) { double d, s; initRandomSeed(); d = rand() / ((double) RAND_MAX + 1); s = d * ((double) high - low + 1); return (int) (floor(low + s)); }
/** * Displays a title screen in an infinite loop. The intent is that this will be called from a * pthread. */ void displayTitleScreen(WINDOW *window) { initColors(); pthread_mutex_init(&mutex, NULL); int maxX = 0; int maxY = 0; getmaxyx(window, maxY, maxX); clear(); printFolly(maxX); attron(COLOR_PAIR(WHITE_ON_BLACK)); mvprintw(14, (maxX - 44)/2, "Press ENTER to continue..."); attroff(COLOR_PAIR(WHITE_ON_BLACK)); move(0, 0); refresh(); usleep(100000); unsigned int randomSeed = (unsigned int)time(NULL); initRandomSeed(randomSeed); int *arg = malloc(sizeof(*arg)); *arg = maxX; pthread_create(&ellipsisThread, NULL, cycleEllipsis, arg); pthread_create(&wanderThread, NULL, cycleWander, arg); while (1) { pthread_mutex_lock(&mutex); move(0, 0); refresh(); pthread_mutex_unlock(&mutex); usleep(10000); } }
void setRandomSeed(int seed) { initRandomSeed(); srand(seed); }
bool randomChance(double p) { initRandomSeed(); return randomReal(0, 1) < p; }