advanced-random-string
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).
Features
- Generate random strings with customizable character sets.
- Use cryptographically secure RNGs for secure string generation.
- Allow users to specify their own RNGs for advanced use cases.
- Predefined character sets for convenience.
Installation
Add advanced-random-string
to your Cargo.toml
:
[]
= "0.1.3"
Usage
Generate a Random String with a Customizable Character Set
use ;
let random_string = generate;
println!;
// Specify a custom charset
let charset = b"MY_CHARSET";
let random_string_with_custom_charset = generate;
println!;
Generate an Unsecure Random String
use ;
let random_string = generate_unsecure;
println!;
Generate a Cryptographically Secure Random String
use ;
let random_string = generate_os_secure;
println!;
Generate a Random String with a User-Specified RNG
use SeedableRng;
use SmallRng;
use ;
let mut rng = from_entropy;
let random_string = generate_with_rng;
println!;
Predefined Character Sets
The library provides some predefined character sets for convenience:
- ALPHANUMERIC
- UPPERCASE
- LOWERCASE
- DIGITS
- HEXADECIMAL
- ALPHABETIC
- BASE62
- BASE64
- ASCII_PRINTABLE
- URLSAFE_BASE64
- BINARY
- OCTAL
- SYMBOLS
- WHITESPACE
- EXTENDED_ASCII
License
This project is licensed under the MIT License. See the LICENSE file for details.