3 releases

0.1.2 Aug 19, 2022
0.1.1 Aug 18, 2022
0.1.0 Aug 18, 2022

#2181 in Algorithms

Download history 52/week @ 2024-03-14 23/week @ 2024-03-21 52/week @ 2024-03-28 64/week @ 2024-04-04 55/week @ 2024-04-11 54/week @ 2024-04-18 59/week @ 2024-04-25 97/week @ 2024-05-02 98/week @ 2024-05-09 149/week @ 2024-05-16 177/week @ 2024-05-23 205/week @ 2024-05-30 268/week @ 2024-06-06 116/week @ 2024-06-13 246/week @ 2024-06-20 196/week @ 2024-06-27

872 downloads per month
Used in basic_trie

MIT license

115KB
1.5K SLoC

Randomizer

pipeline status coverage report Latest Release

Randomizer provides a simple implementation of creating random information, eg random string, and bytes. Thre are many randomization libraries for rust. They are often either complex to use and safe or they are easy to use, but have some significant descrpincies with the code, like using unsafe functions or unwrapping potential Error data. Due to this, i created this library to eliviate those problems.

Generation.

There are 2 (actually 3) types of byte generation. The underneath concept is to generate random bytes for both UTF8 strings and bytes or byte sequences. This generator breaks up the sequence of characters or bytes and from the sequence of combinations it will generate a series of random bytes. if the sequence of bytes are generated from a valid UTF8 string, then each letter can be seperated and used for generating a random sequence of the valid sequences of bytes. This allows for the byte -> UTF8 convertion to be almost infallible.

This also means that if the system is supplied with a set of words the generator can randomly put those words together into a sequence.

Usage

Generate a string

use randomizer::Randomizer;

let string = Randomizer::ALPHANUMERIC(6).string().unwrap();
assert_eq!(string.chars().count(), 6);
let string = Randomizer::new(6, Some("u")).string().unwrap();

assert_eq!(string, "uuuuuu");

Generate a byte value

use randomizer::{Charset, Randomizer};

let bytes = Randomizer::new(6, Some(Charset::AnyByte)).bytes().unwrap();

assert_eq!(bytes.len(), 6);

Generate custom word string

use randomizer::{Charset, Randomizer};

let string = Randomizer::new(6, Some(vec!["foo","bar"])).string().unwrap();

assert_eq!(string.chars().count(), 18);

Simple String generation with constants

its possible to generate a string using the simplification functions for different types

use randomizer::{Randomizer};

let string = Randomizer::ALPHABETICAL(6).string().unwrap();

assert_eq!(string.chars().count(), 6);

Dependencies

~35KB