diff options
author | rafa_99 <rafa99@protonmail.com> | 2020-12-04 03:31:45 +0000 |
---|---|---|
committer | rafa_99 <rafa99@protonmail.com> | 2020-12-04 03:31:45 +0000 |
commit | 7be4deeee60d11e3ae09ddef1147b2a93b183d88 (patch) | |
tree | b566529d788449442b95fe6a2f0ec41e657a7c45 /utils.c | |
parent | 650fb220913f79b5016dcfe1e497493619bf6fa2 (diff) |
Pushed Working Board
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -1,7 +1,8 @@ #include <stdio.h> -#include <unistd.h> #include <stdlib.h> +#include <string.h> #include <time.h> +#include <unistd.h> #include <sys/time.h> #include "utils.h" @@ -10,6 +11,16 @@ int checkIfFileExists(char *path) return access(path, F_OK); } +int numerize(char *string) +{ + int val = 0; + for( int i = 0; i < strlen(string); i++ ) + { + val += string[i]; + } + return val; +} + int lineCounter(FILE *dictionary) { int words = 0; @@ -41,12 +52,12 @@ char* getLine(FILE *dictionary, int lineNumber) return line; } -int getRandomNumber(int min, int max) +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)) + (randtime.tv_usec / 100 - time(NULL))); + srand(((randtime.tv_sec * 100) + time(NULL) * numerize(question)) + ((randtime.tv_usec / 100) - time(NULL) * numerize(question))); return ((rand() % (max - min + 1)) + 1); } |