codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/*** Gibberish Genator (gibgen.c) *** Author: Joseph Bleau *** Date: 9/8/2011 *** *** Description: Generates a blob of text which is ultimately gibberish ***/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define BUFFER_MAX 6000 int main(int argc, char* argv[]){ int i, j, k; /* Loop counters. */ int r1, r2; /* stores random numbers */ char tmp = ' '; /* TODO: These values should come from CLI */ int word_count = 200; /* words to generate */ int max_syl_per_word = 4; /* maximum number of syllables per word */ int punc_every = 5;/* add punctuation every fifth word */ char punctuation[] = {',','.','!','?'}; char* syl[] = {"pel", "en", "rest", "sur", "kal", "forin", "fin", "fe", "ae", "rud", "mon", "lel", "po", "que", "tre", "ust", "za"}; int num_of_syls = 16; int num_of_puncs = 4; srand((unsigned int) time(NULL)); /* Seed RNG */ for (i = 0; i < word_count; ++i) { r1 = rand() % max_syl_per_word + 1; /* Generate an individual word. */ for (j = 0; j < r1; ++j) { r2 = rand() % num_of_syls; /* Pick a random syllable. */ /* If applicable, our first letter needs to be upper-cased. */ if ( tmp == '.' || tmp == '!' || tmp == '?' || i == 0) { for (k = 0; k < strlen(syl[r2]); ++k) if(k==0 && i != 0) putchar((syl[r2][k])-32); else if( k==0 && i == 0 && j == 0 ) putchar((syl[r2][k])-32); else putchar(syl[r2][k]); tmp = ' '; } else printf("%s", syl[r2]); } /* Sprinkle punctuation into our sentence, guarentee that there is a terminating punctuator at the end. */ if (i % punc_every == 0 || i == word_count-1) { r2 = rand() % num_of_puncs + (i == word_count-1) ? 1 : 0; tmp = punctuation[r2]; putchar(tmp); } printf(" "); } return 0; }
Private
[
?
]
Run code
Submit