random_str
Generate random strings, chars, booleans, and numbers.
What can you do?
If you want to create random texts, phone numbers, or passwords, you can use random_str to do so.
Visit the GitHub repository or the Codeberg mirror.
Requirements
You need to have installed cargo on your system.
If you are using Windows, download the installer from the official page
in the following link:
https://www.rust-lang.org/tools/install
If you are using macOS,
GNU/Linux, WSL or a UNIX based system just type:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
How to use it
Create a project.
cargo new my_project
In your Cargo.toml file, add the following dependency:
[dependencies]
random_str = "1.1.0"
Use cargo build to download the dependency.
cargo build
In your main.rs file write the following:
use random_str::random::{self, CharBuilder, RandomCharBuilder, RandomStringBuilder};
fn main() {
let random_letter: Option<char> = RandomCharBuilder::new()
.with_lowercase()
.with_uppercase()
.build();
println!("Random letter: {}", random_letter.unwrap());
let random_symbol: Option<char> = RandomCharBuilder::new()
.with_symbols()
.build();
println!("Random symbol: {}", random_symbol.unwrap());
let random_number = random::number(0..9);
println!("Random number: {}", random_number);
let another_random_number = random::number(1.0..2.0);
println!("Random float number: {}", another_random_number);
let digits: Option<String> = RandomStringBuilder::new()
.with_length(10)
.with_numbers()
.build();
let random_phone_number = format!("+52 {}", digits.unwrap());
println!("Random phone number: {}", random_phone_number);
let random_password: Option<String> = RandomStringBuilder::new()
.with_length(32) .with_lowercase()
.with_uppercase()
.with_numbers()
.with_symbols()
.build();
println!("Random password: {}", random_password.unwrap());
let random_bool = random::bool();
println!("Random bool: {}", random_bool);
}
Use cargo run to test the result.
cargo run
Possible output:
Random letter: C
Random symbol: Random number: 5
Random float number: 1.487004718282926
Random phone number: +52 11932115293
Random password: M29Fd*tamf3spJxxZOVZRUil!vBjycUHD
Random bool: true
How to contribute
If you think there is a function that may be helpful, you can open a pull request. Please, write your commits using Conventional Commits.
License
This project is licensed under the MIT license. See the LICENSE file for more information.
Credits
Made with ♥️ by DeimosHall.