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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use ;
/// Generates a random integer within the specified range (inclusive).
///
/// # Parameters
///
/// * `min`: The minimum value (inclusive) for the generated random number.
/// * `max`: The maximum value (inclusive) for the generated random number.
///
/// # Returns
///
/// An integer randomly selected within the range from `min` (inclusive) to `max` (inclusive).
///
/// # Example
///
/// ```rust
/// use helpers::rand::min_max;
///
/// let random_number = min_max(1, 10);
/// println!("{}", random_number); // Prints a random number between 1 and 10 (inclusive)
/// ```
/// Generate a random floating-point number within a specified range
///
/// # Parameters
///
/// - `min`: The minimum value of the range (inclusive)
/// - `max`: The maximum value of the range (inclusive)
///
/// # Returns
///
/// A random `f64` value between `min` and `max`
///
/// # Examples
///
/// ```rust
/// let random_val = min_max_float(0.0, 10.0);
/// println!("Random float between 0 and 10: {}", random_val);
/// ```
///
/// # Panics
///
/// - Panics if `min` is greater than `max`
/// - Uses thread-local random number generator
/// Generate a random boolean value
///
/// # Returns
///
/// A random `bool` with a 50% probability of being true or false
///
/// # Examples
///
/// ```rust
/// let coin_flip = random_bool();
/// println!("Random boolean: {}", coin_flip);
/// ```
///
/// # Notes
///
/// - Uses a thread-local random number generator
/// - Probability of `true` is exactly 0.5
/// Randomly select an element from a slice
///
/// # Type Parameters
///
/// - `T`: The type of elements in the slice
///
/// # Parameters
///
/// - `slice`: A reference to a slice of elements
///
/// # Returns
///
/// - `Some(&T)` containing a randomly chosen reference to an element
/// - `None` if the slice is empty
///
/// # Examples
///
/// ```rust
/// let fruits = vec!["apple", "banana", "cherry"];
/// if let Some(fruit) = random_choice(&fruits) {
/// println!("Randomly selected fruit: {}", fruit);
/// }
/// ```
///
/// # Notes
///
/// - Uses thread-local random number generator
/// - Returns `None` for empty slices
/// Randomly shuffle the elements of a mutable slice in-place
///
/// # Type Parameters
///
/// - `T`: The type of elements in the slice
///
/// # Parameters
///
/// - `slice`: A mutable reference to a slice of elements
///
/// # Examples
///
/// ```rust
/// let mut numbers = vec![1, 2, 3, 4, 5];
/// shuffle(&mut numbers);
/// println!("Shuffled numbers: {:?}", numbers);
/// ```
///
/// # Notes
///
/// - Modifies the slice in-place
/// - Uses the Fisher-Yates (Knuth) shuffle algorithm
/// - Uses thread-local random number generator