Skip to main content

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 alphabets
    • C - All uppercase ascii alphabets
    • i - 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 the format 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 text
    • pC - Generate uppercase pronouncable text
    • pcC - Generate pronouncable text with characters that are randomly lower or uppercase
    • dc - Generate lowercase dictionary text
    • dC - Generate uppercase dictionary text
    • dcC - 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 letters

    randtext.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. The organize_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
      
      

Metadata

Release files for randtext 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for randtext 0.1.3
File Size Uploaded Provenance Actions
randtext-0.1.3.tar.gz 106.1 kB Without provenance Details for randtext-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for randtext 0.1.3
File Interpreter ABI Platform Actions
randtext-0.1.3-py3-none-any.whl Python 3 none any Details for randtext-0.1.3-py3-none-any.whl

Total release size: 212.8 kB

Release files / randtext-0.1.3.tar.gz

Download URL randtext-0.1.3.tar.gz
Size 106.1 kB
Tags Source
SHA-256 checksum
How to use checksums
95fef64db0eb015e6b05440c30ac09de1d2de49e496fdd87c766986b9113da8d
BLAKE2b-256 checksum
How to use checksums
b73de25c9168b85f47d44539582c1975b1fda011ed52cfbd48d94d8bec08e2d3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / randtext-0.1.3-py3-none-any.whl

Download URL randtext-0.1.3-py3-none-any.whl
Size 106.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a071bf2744aa58b2995f8adf900faffcd5e31d4b38530841c21540962204f02
BLAKE2b-256 checksum
How to use checksums
90e7b767a834b629e302812151d843754abf7fd8b7529eb729a74da03f5a3e19
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for randtext 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page