Skip to main content

Crate flabild

Crate flabild 

Source
Expand description

§Fake Words Generator

A Markov chain-based fake word generator that produces pronounceable pseudo-words based on character transition probabilities.

This library uses a second-order Markov chain model trained on real words to generate realistic-looking fake words.

The probability weights are pre-computed and embedded in the binary, making the generator self-contained with no external dependencies at runtime.

§Features

  • Fast generation: Uses Walker’s alias method for O(1) weighted random selection
  • Embedded weights: No external files needed at runtime
  • Pronounceable output: Generates words that look and sound like real words
  • Thread-safe: Chooser implements Send and Sync

§Quick Start

use flabild::Chooser;

// Create a generator
let chooser = Chooser::new();

// Generate a fake word
let word = chooser.word().expect("Failed to generate word");
println!("Generated word: {}", word);

§Examples

§Basic Usage

use flabild::Chooser;

let chooser = Chooser::new();
let word = chooser.word().unwrap();
assert!(!word.is_empty());
println!("Random fake word: {}", word);

§Generating Multiple Words

use flabild::Chooser;

let chooser = Chooser::new();

// Generate 10 fake words
for i in 1..=10 {
    match chooser.word() {
        Ok(word) => println!("{}. {}", i, word),
        Err(e) => eprintln!("Error generating word {}: {}", i, e),
    }
}

§Error Handling

use flabild::Chooser;

let chooser = Chooser::new();

match chooser.word() {
    Ok(word) => println!("Generated: {}", word),
    Err(e) => {
        // Handle errors (missing weights or exceeded max length)
        eprintln!("Word generation failed: {}", e);
    }
}

§Using try_new for Fallible Initialization

use flabild::Chooser;

// Use try_new if you want to handle initialization errors
match Chooser::try_new() {
    Ok(chooser) => {
        let word = chooser.word().unwrap();
        println!("Generated: {}", word);
    }
    Err(e) => {
        eprintln!("Failed to initialize chooser: {}", e);
    }
}

§Reusing the Generator

use flabild::Chooser;

// Create once and reuse - more efficient than creating multiple times
let chooser = Chooser::new();

let words: Vec<String> = (0..100)
    .filter_map(|_| chooser.word().ok())
    .collect();

println!("Generated {} words", words.len());

Structs§

Chooser
A fake words generator using Markov chains.

Constants§

CHARS
Available characters in the alphabet, including word boundary markers.

Type Aliases§

Choices
Maps character pairs to their successor probability distributions.
Pair
A character pair used as a Markov chain state.
Weights
Probability weights for each character in the alphabet.