Skip to content

Rust library to generate random strings, chars, booleans, and integers

License

Notifications You must be signed in to change notification settings

DeimosHall/random_str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

random_str

Generate random strings, chars, booleans, and integers.

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: https://github.com/DeimosHall/random_str

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 = "0.1.2"

Use cargo build to download the dependency.

cargo build

In your main.rs file write the following:

use random_str as random;

fn main() {
    let lowercase = true;
    let uppercase = true;

    let random_letter = random::get_letter(lowercase, uppercase);
    println!("Random letter: {}", random_letter);

    let random_symbol = random::get_symbol();
    println!("Random symbol: {}", random_symbol);

    let mut min = 0;
    let mut max = 9;
    let random_number = random::get_int(min, max);
    println!("Random number: {}", random_number);

    min = 1000000;
    max = 9999999;
    let seven_digits = random::get_int(min, max); // 7 digits
    let random_phone_number = format!("+52 343{}", seven_digits);
    println!("Random phone number: {}", random_phone_number);

    let length = 16;
    let numbers = true;
    let symbols = true;
    let random_password = random::get_string(length, lowercase, uppercase, numbers, symbols);
    println!("Random password: {}", random_password);

    let random_bool = random::get_bool();
    println!("Random bool: {}", random_bool);

    let random_char = random::get_char();
    println!("Random char: {}", random_char);
}

Use cargo run to test the result.

cargo run

Possible output:

random_str on  main [!] via 🦀 v1.69.0
❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/main`
Random letter: b
Random symbol: $
Random number: 7
Random phone number: +52 3431550168
Random password: ovnaLx1A%NCric1H
Random bool: true
Random char: ^

How to contribute

If you think there is a function that may be helpful, you can open a pull request. Please, follow the next steps.

  1. Make a fork of the repository.

Note: Be sure to uncheck the option Copy the main branch only.

  1. Clone the repositoy.
git clone https://github.com/username/random_str.git

Note: Replace username with your Github username.

  1. Change to the contribute branch.
git checkout contribute
  1. Update the contribute branch.
git merge main
  1. Commit your changes using Conventional Commits. For example:
git commit -m "feat: add random float"
  1. Push your changes to the contribute branch.
git push origin contribute
  1. Open a pull request. I will check it and make the merge to the main branch.

About

Rust library to generate random strings, chars, booleans, and integers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages