]>
Commit | Line | Data |
---|---|---|
1d8fe1f7 MR |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <string.h> | |
4 | #include <stdint.h> | |
5 | ||
6 | #define MAX_LINE 4096 | |
7 | ||
8 | void generate_random_word(char* buffer, size_t length) { | |
9 | for (size_t i = 0; i < length; i++) { | |
10 | buffer[i] = 'a' + (rand() % 26); | |
11 | } | |
12 | buffer[length - 1] = 0; | |
13 | } | |
14 | ||
15 | int main(int argc, char** argv) { | |
16 | if (argc != 3) { | |
17 | printf("usage: %s <wordlist filename> <num words>\n", argv[0]); | |
18 | return EXIT_FAILURE; | |
19 | } | |
20 | ||
21 | char* filename = argv[1]; | |
22 | uint32_t num_words = atol(argv[2]); | |
23 | ||
24 | ||
25 | FILE* fp = fopen(filename, "w"); | |
26 | char* buffer = calloc(sizeof(char), MAX_LINE); | |
27 | const int shortest_guess = 2; | |
28 | const int longest_guess = 15; | |
29 | ||
30 | for (uint32_t i = 0; i < num_words; i++) { | |
31 | generate_random_word(buffer, shortest_guess + | |
32 | (rand() % (longest_guess - shortest_guess))); | |
33 | fprintf(fp, "%s\n", buffer); | |
34 | } | |
35 | ||
36 | fclose(fp); | |
37 | free(buffer); | |
38 | } |