JohnL4 / Markovian-text

Python script to randomly generate some text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Silly little Python script to generate random gibberish based on sample text.

The idea is that it builds frequency tables of “what’s next” based on “what came before”. You pick the length of “what came before” (k).

So, if you have a sample input file that looks like:

Albertville
Farmville
Farmingdale
Wilmington

and you manage to build the random sequence “ill”, you’ll definitely get “e” as your next letter (if k = 3).

But if you build the random sequence “ing”, then you might get a “d” or “t” as the next letter (50% chance). Ditto “arm” leading to either “i” or “v”.

Likewise, if you feed it the Gettysburg Address, you’ll get some Lincolnesque gibberish (k = 4 seems to be a good minimum).

For town names, you probably want k = 3 and --preserveLineBreaks, but for just a stream of text, you probably don’t want that. (Note also, if you’re really trying to generate random town names, you’ll probably wind up with some exact copies of existing towns, so check your spiffy new town name against the input if you care about that.)

Alsø, if you want lists of town names, this site seems decent and easy: https://www.westvirginia-demographics.com/cities_by_population. Substitute the state you want.

About

Python script to randomly generate some text

License:MIT License


Languages

Language:Python 100.0%