1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! src/generate.rs
use ;
/// Generates a random string of a specified length using a given character set.
///
/// # Arguments
///
/// * `length` - The length of the generated string.
/// * `charset` - A slice of bytes representing the character set to use for generating the string.
///
/// # Returns
///
/// A `String` containing randomly selected characters from the provided character set.
///
/// # Examples
///
/// ```
/// 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);
/// ```
/// Generates a unsecure random string with SmallRng of a specified length using a given character set.
///
/// # Arguments
///
/// * `length` - The length of the generated string.
/// * `charset` - A slice of bytes representing the character set to use for generating the string.
///
/// # Returns
///
/// A `String` containing randomly selected characters from the provided character set.
///
/// # Examples
///
/// ```
/// use advanced_random_string::{charset, random_string};
///
/// let random_string = random_string::generate_unsecure(10, charset::BASE62);
/// println!("Generated string: {}", random_string);
/// ```
/// Generates a secure random string with OsRng of a specified length using a given character set.
///
/// # Arguments
///
/// * `length` - The length of the generated string.
/// * `charset` - A slice of bytes representing the character set to use for generating the string.
///
/// # Returns
///
/// A `String` containing randomly selected characters from the provided character set.
///
/// # Examples
///
/// ```
/// use advanced_random_string::{charset, random_string};
///
/// let random_string = random_string::generate_os_secure(10, charset::BASE62);
/// println!("Generated string: {}", random_string);
/// ```
/// Generates a random string of a specified length using a given character set and RNG.
///
/// # Arguments
///
/// * `length` - The length of the generated string.
/// * `charset` - A slice of bytes representing the character set to use for generating the string.
/// * `rng` - A mutable reference to an RNG implementing the `Rng` trait.
///
/// # Returns
///
/// A `String` containing randomly selected characters from the provided character set.
///
/// # Examples
///
/// ```
/// 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);
/// ```