summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ouija.c1
-rw-r--r--session.c2
-rw-r--r--session.h3
-rw-r--r--utils.c9
-rw-r--r--utils.h10
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 <stdio.h>
#include <stdlib.h>
#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 <stdio.h>
#include <stdlib.h>
#include <string.h>
-#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 <stdio.h>
+/* 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);