Crates.io | advanced-random-string |
lib.rs | advanced-random-string |
version | 0.1.3 |
source | src |
created_at | 2024-06-03 06:04:39.322281 |
updated_at | 2024-06-03 06:30:34.751705 |
description | Provides advanced string generation based on given charsets, lengths, and RNGs. |
homepage | |
repository | https://github.com/mcclementines/advanced-random-string |
max_upload_size | |
id | 1259754 |
size | 11,641 |
advanced-random-string
is a Rust library for generating random strings with customizable character sets. It supports both basic and cryptographically secure random number generators (RNGs).
Add advanced-random-string
to your Cargo.toml
:
[dependencies]
advanced-random-string = "0.1.3"
use advanced_random_string::{charset, random_string};
let random_string = random_string::generate(10, charset::BASE62);
println!("Generated string: {}", random_string);
// Specify a custom charset
let charset = b"MY_CHARSET";
let random_string_with_custom_charset = random_string::generate(10, charset);
println!("Generated string: {}", random_string_with_custom_charset);
use advanced_random_string::{charset, random_string};
let random_string = random_string::generate_unsecure(10, charset::BASE62);
println!("Generated string: {}", random_string);
use advanced_random_string::{charset, random_string};
let random_string = random_string::generate_os_secure(10, charset::BASE62);
println!("Generated string: {}", random_string);
use rand::SeedableRng;
use rand::rngs::SmallRng;
use advanced_random_string::{charset, random_string};
let mut rng = SmallRng::from_entropy();
let random_string = random_string::generate_with_rng(10, charset::BASE62, &mut rng);
println!("Generated string: {}", random_string);
The library provides some predefined character sets for convenience:
This project is licensed under the MIT License. See the LICENSE file for details.