From 5eba64da58978824f99259ea221a13b21f335a21 Mon Sep 17 00:00:00 2001 From: rafa_99 Date: Tue, 15 Dec 2020 23:05:17 +0000 Subject: Added Documentation and Updated Fast Seeded Number Generator --- ouija.c | 1 + session.c | 2 +- session.h | 3 ++- utils.c | 9 ++++----- utils.h | 10 ++++++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ouija.c b/ouija.c index aab31c5..c55737f 100644 --- a/ouija.c +++ b/ouija.c @@ -1,6 +1,7 @@ #include #include #include "session.h" +#include "utils.h" int main(int argc, char **argv) { diff --git a/session.c b/session.c index 205e92f..e3b8702 100644 --- a/session.c +++ b/session.c @@ -1,7 +1,7 @@ #include #include #include -#include "session.h" +#include "utils.h" void startSession(FILE *dictionary) { diff --git a/session.h b/session.h index f02c7e1..989fd65 100644 --- a/session.h +++ b/session.h @@ -1,3 +1,4 @@ -#include "utils.h" +#include +/* Starts a oujia session using a inputted dictionary file */ void startSession(FILE *dictionary); diff --git a/utils.c b/utils.c index e349368..83bfdd2 100644 --- a/utils.c +++ b/utils.c @@ -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); } diff --git a/utils.h b/utils.h index 6cfbc80..0903c86 100644 --- a/utils.h +++ b/utils.h @@ -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); -- cgit v1.2.3