diff options
-rw-r--r-- | ouija.c | 1 | ||||
-rw-r--r-- | session.c | 2 | ||||
-rw-r--r-- | session.h | 3 | ||||
-rw-r--r-- | utils.c | 9 | ||||
-rw-r--r-- | utils.h | 10 |
5 files changed, 18 insertions, 7 deletions
@@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include "session.h" +#include "utils.h" int main(int argc, char **argv) { @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "session.h" +#include "utils.h" void startSession(FILE *dictionary) { @@ -1,3 +1,4 @@ -#include "utils.h" +#include <stdio.h> +/* Starts a oujia session using a inputted dictionary file */ void startSession(FILE *dictionary); @@ -54,10 +54,9 @@ char* getLine(FILE *dictionary, int lineNumber) int getRandomNumber(int min, int max, char *question) { - // Adding Randomize Time Values for Less Chances of Running into Seed Collisions - struct timeval randtime; - gettimeofday(&randtime,NULL); - srand(((randtime.tv_sec * 100) + time(NULL) * numerize(question)) + ((randtime.tv_usec / 100) - time(NULL) * numerize(question))); + struct timespec s; + clock_gettime(CLOCK_REALTIME, &s); + srand(s.tv_nsec * numerize(question)); - return ((rand() % (max - min + 1)) + 1); + return ((rand() % (max - min + 1)) + min); } @@ -2,8 +2,18 @@ #define MAX_LINE 256 +/* Checks if a file exists */ int checkIfFileExists(char *path); +/* Turns a string into a number by + * using the sum of its ascii values. + */ int numerize(char *string); +/* Counts the lines from a dictionary file */ int lineCounter(FILE *dictionary); +/* Returns a specified line from a dictionary file */ char* getLine(FILE *dictionary, int line); +/* Returns a random number within the inclusive number range + * and based on the inputted question. + * Uses a fast seeded number generator. + */ int getRandomNumber(int min, int max, char *question); |