Generate random text with a considerable amount of control
Project description
randtext
This module can be used to generate random text in python. It can be used to generate text with
- Meaningless mishmash of characters
- Pronouncable mishmash of characters
- Random dictionary words
Usage
Import the module in your project like this
from randtext import randtext
You only need to use the following method to generate random text. The format
argument is a string containing the instructions for generating the random text. The structure of the format
argument is discussed below.
randtext.generate(format)
Format argument
The format
argument is a comma separated list of instructions that will be used by randtext to generate the random text.
The instruction must be a number followed by the operation type or a list of characters to randomly choose from. The number represents the number of characters that you want within that sequence. The other half of the instruction can be of two types
- Combinable operations - The following operations can be combined together to define the list of characters that randtext will randomly choose from to generate the text
c
- All lowercase ascii alphabetsC
- All uppercase ascii alphabetsi
- All integers from 0-9- special characters - Any special character can be used based on your need other than
,
because it is used to delimit the instructions in theformat
argument. You can even use a space if you want.
- Non combinable operations - These operations can not be combined with other operations. If you do try to combine them with other operations then they will regarded as just another character in the list of characters to randomly generate meaningless text from
pc
- Generate lowercase pronouncable textpC
- Generate uppercase pronouncable textpcC
- Generate pronouncable text with characters that are randomly lower or uppercasedc
- Generate lowercase dictionary textdC
- Generate uppercase dictionary textdcC
- Generate dictionary text with characters that are randomly lower or uppercase
Examples
-
Simple meaningless random text with 14 ascii lowercase and uppercase characters
randtext.generate('14cC') # 5 sample outputs: # ZWUvhxquyeNlWh # SarqpCypLJrEWe # GhFLSmQWyMISaN # gdDcRzOthCqUpw # oGUbsyHHfcaNeB
-
Start the text with 2 of
#$%&()[]{}<>
characters, then 2 numbers, then 1 random uppercase letter, then 5 intergers, or lowercase and uppercase lettersrandtext.generate('2#$%&()[]{}<>,2i,1C,5icC') # 5 sample outputs: # %>62F9134f # }%12FaLe5j # {{11H82R2i # [%73UOVuk3 # %{01EG8rG6
-
Create 2 pronouncable (but still meaningless) words with 8 characters each and separated by a space. The first word must start with a random uppercase letter and the rest of the letters should be all lowercase. The second word must have random lowercase and uppercase characters.
randtext.generate('1C,7pc,1 ,8pcC') # 5 sample outputs: # Ceaskeff aUcLavio # Dbaidirh eagHAusk # Uiayausk eENAUSTO # Zshaiweb aistEayA # Hiweegup NougUGhA
-
Create 2 dictionary words with 10 characters each separated by a space
randtext.generate('10dc,1 ,10dc') # 5 sample outputs: # courteous sumptuous # brimstone riverbank # memoranda embroider # stimulant promenade # proselyte conqueror
Notes
- The dictionary uses words found here and I take no responsibility for the words output by the dictionary operation.
-
Feel free to delete or add your own words from the files in the
dictionary
directory of your local cloned copy of the repo. -
The name of each file in the
dictionary
directory is the same as the number of characters in each line of the file. Theorganize_dictionary.py
script can be used to read a raw dictionary file with words of all lengths and create the numbered files required by randtext -
The number of words with a given length in the dictionary used here is as follows:
Length | # of words -------+------------ 2 | 26 3 | 136 4 | 783 5 | 2207 6 | 3210 7 | 3910 8 | 4126 9 | 3708 10 | 3151 11 | 2021 12 | 1140 13 | 588 14 | 288 15 | 113 16 | 44 17 | 19 18 | 8 19 | 4 21 | 2 22 | 2 23 | 1
-
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file randtext-0.1.3.tar.gz
.
File metadata
- Download URL: randtext-0.1.3.tar.gz
- Upload date:
- Size: 106.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95fef64db0eb015e6b05440c30ac09de1d2de49e496fdd87c766986b9113da8d |
|
MD5 | f1ca3e3bfe3df2e7ba6eac77d41e6d5f |
|
BLAKE2b-256 | b73de25c9168b85f47d44539582c1975b1fda011ed52cfbd48d94d8bec08e2d3 |
File details
Details for the file randtext-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: randtext-0.1.3-py3-none-any.whl
- Upload date:
- Size: 106.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a071bf2744aa58b2995f8adf900faffcd5e31d4b38530841c21540962204f02 |
|
MD5 | 34d68d4cf5b70fb1c6b0815ca022a7d4 |
|
BLAKE2b-256 | 90e7b767a834b629e302812151d843754abf7fd8b7529eb729a74da03f5a3e19 |