11 releases

0.3.6 Sep 16, 2023
0.3.5 Jun 25, 2023
0.3.4 Apr 1, 2023
0.3.3 Feb 25, 2023
0.1.0 Sep 8, 2020

#125 in Development tools

Download history 11/week @ 2023-11-20 108/week @ 2023-11-27 217/week @ 2023-12-04 201/week @ 2023-12-11 401/week @ 2023-12-18 38/week @ 2023-12-25 400/week @ 2024-01-01 279/week @ 2024-01-08 260/week @ 2024-01-15 358/week @ 2024-01-22 298/week @ 2024-01-29 475/week @ 2024-02-05 491/week @ 2024-02-12 382/week @ 2024-02-19 610/week @ 2024-02-26 341/week @ 2024-03-04

1,836 downloads per month
Used in sinais

BSD-3-Clause

70KB
1.5K SLoC

random_name_generator

Crates.io Crates.io License Build and Test

This is a rust port of the Ruby port of the Java Random Name Generator library.

It generates it's results based upon which language file is specified. Currently, the following are supported in both English and Russian:

Thanks to Zhumatiy Sergey, for his contribution of the Russian language files, originally in the Ruby version of this library!

The following are in progress:

Using the library

use rnglib::{RNG, Language};

fn main() {
    let rng = RNG::try_from(&Language::Elven).unwrap();
    
    let first_name = rng.generate_name();
    let last_name = rng.generate_name();
    
    println!("{}: {} {}", rng.name, first_name, last_name)
}

It is possible to control the number of syllables for a generated name:

use rnglib::{RNG, Language};

fn main() {
    let rng = RNG::try_from(&Language::Fantasy).unwrap();
    let name = rng.generate_name_by_count(3);
    println!("{}: {}", rng.name, name)
}

One can also pass in custom language files:

use rnglib::{RNG};

fn main() {
    let rng = RNG::new_from_file("src/languages/Test-tiny.txt").unwrap();
    let name = rng.generate_name();
    println!("{}: {}", rng.name, name)
}

Running the binary

To get information about the available options, run help.

Using cargo:

$> cargo run -- --help
Random Name Generator

Usage: rng [OPTIONS]

Options:
  -d, --demonic
  -e, --elven
  -f, --fantasy
  -g, --goblin
  -r, --roman
  -c, --curse            [UNDER CONSTRUCTION]
  -x, --flipmode         Flipmode is the greatest! (Random language)
      --russian          Use Russian language file, if available
      --short            Creates shorter names
      --raw <FILE>       Reads in a raw language file
  -n, --number <number>  Number of names created. [default: 2]
  -h, --help             Print help
  -V, --version          Print version

or from the binary:

$> rng --help

Passing in one of the language flags will generate a name using that Language's source file.

From cargo:

$> cargo run -- -g
Goblin: zradogul bargodul

It also now supports Russian language files:

❯ cargo run -- --roman --russian
Римский: Дафрибуцио Дубенус

❯ cargo run -- --goblin --russian
Гоблин: Краог Зрашагул

❯ cargo run -- --fantasy --russian
Фантазия: Валорнен Гарлакот

❯ cargo run -- --elven --russian
Эльфийский: Латэнаэлмасан Шелиан

From the binary:

$> rng -e
Elven: daedar latherdre

Dependencies

Dev Dependencies

TODO

  • Finish curse words
  • Add syllable weight flag
  • Add number of names flag

Further Interest

Dependencies

~5.5–7.5MB
~114K SLoC