We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 73d52fb commit 5d16e2dCopy full SHA for 5d16e2d
Cargo.toml
@@ -6,3 +6,4 @@ edition = "2021"
6
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
8
[dependencies]
9
+rand = "0.8.4"
src/lib.rs
@@ -1,4 +1,5 @@
1
pub mod linked_list;
2
pub mod queue;
3
+pub mod random;
4
pub mod sorting;
5
pub mod stack;
src/random/mod.rs
@@ -0,0 +1,8 @@
+use rand::Rng;
+
+pub fn fisher_yates_shuffle<T: Ord>(arr: &mut [T]) {
+ for i in (1..arr.len()).rev() {
+ let j = rand::thread_rng().gen_range(0..=i);
+ arr.swap(i, j);
+ }
+}
0 commit comments