Skip to content

Commit

Permalink
Chapter 3: Add random seed to output.c
Browse files Browse the repository at this point in the history
for better randomness of word choices
  • Loading branch information
asankov committed May 8, 2020
1 parent a43f118 commit bf10c68
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chapter-3/3.4-generating-output/output.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <time.h>

#include "../3.3-building-the-data-structure-in-c/structs.c"

void generate(int nwords)
Expand Down Expand Up @@ -49,6 +51,10 @@ int main(void)
for (int i = 0; i < NPREF; i++)
prefix[i] = NONWORD;

long seed = time(NULL);

srand(seed);

FILE *f = fopen("text.txt", "r");
if (f == NULL)
return 1;
Expand All @@ -58,4 +64,4 @@ int main(void)
// printt();
generate(MAXGEN);
return 0;
}
}

0 comments on commit bf10c68

Please sign in to comment.