Random Slug Generator
What it says on the tin - this generates random text slugs in Rust.
PyPi
Usable as a standalone binary, web applications as a WebAssembly module (WASM), or even as a Python module.
Why?
I needed a way to generate random slugs for a web project so thought it was a good opporunity to try out Rust's WebAssembly capabilities while also being able to use the same code as a zero-dependency python module for other projects.
Key features
- Generates unique random slugs for a input length in words
- Fast
- Zero dependencies (python and wasm)
- Pre-filtered to avoid dodgy or rude vocabulary
- Customisable slug length in words
- Over half a million unique combinations for 2-word slugs ranging up to over 280 trillion unique combinations for 5-word slugs.
Usage
As a Python module
Install from PyPI
OR
Build from source
Then from Python:
: =
# slugs: ['reflecting-unsealed-mamba', 'disabling-addicting-asp', 'pliable-begotten-barnacle', 'vaulting-telepathic-caracal', 'canonical-graven-beetle']
Other features:
get_slug(word_length: int) -> str: Generate a single slug of a specific lengthSlugGenerator(word_length: int): Create a generator object to generate slugs of a specific length. Will generate slugs until all unique permutations have been reached.= # 'unwieldy-unsuspecting-ant'combinations(word_length: int) -> int: Get the number of possible combinations for a given word length# 556,284EternalSlugGenerator(word_length: int): Create iteration suffixed slugs forever. Guaranteed uniqueness.= = # max no of combinations iterated # 'listening-tench-0' # 'existent-walrus-1'
Python Performance
- 0.5 million x 2 word slugs: ~210ms
- 1 million x 5 word slugs: ~524ms
As a WASM module
# If wasm pack is not already installed
# build the WASM module
Then from JS/TS:
import init, { random_slugs } from './pkg/rustyrs.js';
init();
const slugs: string[] = random_slugs(3, 5);
console.log(slugs);
// slugs: ['postpartum-regal-taipan', 'devastating-elven-salamander', 'immense-ambivalent-wren', 'philosophical-bandaged-gaur', 'outlaw-noncommercial-sunfish']
See index.html for a full example
As a Rust binary
As a standalone binary
Example Output
proctor-slimmer-guillemot
unsafe-warlike-avocado
garbled-pulled-stork
answerable-quick-whale
floral-apportioned-bobcat
License
MIT