| Crates.io | random-zh |
| lib.rs | random-zh |
| version | 0.1.3 |
| created_at | 2025-06-20 23:29:58.50235+00 |
| updated_at | 2025-06-21 09:22:00.689243+00 |
| description | A Rust crate for generating random Chinese characters. |
| homepage | |
| repository | https://github.com/WantenMN/random-zh.git |
| max_upload_size | |
| id | 1720370 |
| size | 76,554 |
A Rust crate to generate random Chinese characters based on various criteria.
Add random-zh to your Cargo.toml:
[dependencies]
random-zh = "0.1.3"
Run the following command to fetch the crate:
cargo build
use random_zh::{random_zh, RandomZhOptions};
// Get a random character
let random_character = random_zh(RandomZhOptions::default());
// Get 10 random characters
let ten_random_characters = random_zh(RandomZhOptions {
count: Some(10),
..Default::default()
});
// Get characters within a level range
let characters_in_level_range = random_zh(RandomZhOptions {
level_range: Some((1, 3)),
..Default::default()
});
// Get characters within a stroke count range
let characters_in_stroke_count_range = random_zh(RandomZhOptions {
stroke_count_range: Some((5, 10)),
..Default::default()
});
// Get characters within a level range and stroke count range
let characters_within_ranges = random_zh(RandomZhOptions {
level_range: Some((1, 3)),
stroke_count_range: Some((5, 10)),
..Default::default()
});
// Allow duplicates
let characters_with_duplicates = random_zh(RandomZhOptions {
count: Some(20),
allow_duplicates: true,
..Default::default()
});
random_zh(options: RandomZhOptions) -> Vec<char>Generates a vector of random Chinese characters based on the provided options.
RandomZhOptionscount: Option<usize>: The number of random characters to generate. Defaults to 1 if not specified.level_range: Option<(u8, u8)>: The range of levels to include in the generated characters. Levels currently range from 1 to 3.stroke_count_range: Option<(u8, u8)>: The range of stroke counts to include in the generated characters. Stroke counts currently range from 1 to 36.allow_duplicates: bool: Whether to allow duplicate characters in the output. Defaults to false, if count exceeds the total number of unique characters, only the total number of unique characters will be returned instead of countlet options = RandomZhOptions {
count: Some(5),
level_range: Some((1, 2)),
stroke_count_range: Some((8, 12)),
allow_duplicates: false,
};
let characters = random_zh(options);
println!("Random characters: {:?}", characters);
The random-zh binary allows generating random Chinese characters from the command line.
cargo install random-zh
Usage: random-zh [OPTIONS]
Options:
-c, --count <COUNT>
Number of characters to generate
-l, --level-range <LEVEL_RANGE>
Level range for characters (e.g., 1,3 for levels 1 to 3, 1,1 for level 1 only)
-s, --stroke-count-range <STROKE_COUNT_RANGE>
Stroke count range for characters (e.g., 1,36 for 1 to 36 strokes, 1,1 for 1 stroke only)
-d, --allow-duplicates
Allow duplicate characters
-h, --help
Print help
-V, --version
Print version
random-zh
# ['天']
random-zh -c 10
# ['稠', '𬭤', '霪', '悸', '垸', '腑', '姒', '运', '迨', '霭']
random-zh -c 10 -l 1,1
#['茎', '雷', '除', '暑', '颗', '目', '厉', '举', '槛', '瓶']
random-zh -c 10 -l 1,1 -s 1,1
# ['乙', '一']
random-zh -c 10 -l 1,1 -s 1,1 -d
# ['乙', '一', '一', '一', '一', '乙', '乙', '一', '一', '一']
This project is licensed under the MIT License.