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
// Copyright 2025 Shingo OKAWA. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! This module contains a set of extensions of the existing Rust types.
/// A trait providing extension methods for slices.
///
/// This trait adds several useful methods for working with slices. It provides:
/// - [`choose`]: Randomly selects an element from the slice.
/// - [`choose_mut`]: Randomly selects and mutably borrows an element from the slice.
/// - [`shuffle`]: Shuffles the slice in place.
///
/// These methods operate on slices of any type `T` and assume that `T` is a type
/// that can be accessed and modified within the slice.
///
/// # Examples
/// ```
/// use regd_testing::prelude::*;
///
/// let mut numbers = [1, 2, 3, 4, 5];
/// numbers.shuffle();
/// println!("Shuffled numbers: {:?}", numbers);
///
/// if let Some(choice) = numbers.choose() {
/// println!("Random choice: {}", choice);
/// }
///
/// if let Some(choice) = numbers.choose_mut() {
/// *choice = 10;
/// println!("Modified choice: {}", choice);
/// }
/// ```
///
/// [`choose`]: Self::choose
/// [`choose_mut`]: Self::choose_mut
/// [`shuffle`]: Self::shuffle
/// Generates a random index within the specified upper bound.
///
/// This function returns a random integer between 0 (inclusive) and `sup` (exclusive),
/// using a range-based random number generation strategy. It intelligently chooses between
/// using a `u32` or `usize` bound based on the value of `sup`, ensuring the appropriate
/// range is selected for generating random numbers.
///
/// # Parameters
/// - `sup`: The upper bound (exclusive) for the generated random index. The function
/// handles both small and large upper bounds, using a `u32` range for smaller values
/// and a `usize` range for larger values.
///
/// # Returns
/// - A random `usize` integer in the range `[0, sup)`.