We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7280425 commit b8586ceCopy full SHA for b8586ce
1 file changed
Fisher-Yates/Go/jcla1_fisher_yates.go
@@ -0,0 +1,20 @@
1
+package fisherYates
2
+
3
+import (
4
+ "math/rand"
5
+)
6
7
+// Make sure you seed the PRNG before using this function
8
+// Fisher-Yates shuffle runs in O(n) and uses O(1) space
9
+func fisherYates(arr []int) []int {
10
+ m := len(arr)
11
+ var i int
12
13
+ for m != 0 {
14
+ i = rand.Intn(m)
15
+ m -= 1
16
+ arr[i], arr[m] = arr[m], arr[i]
17
+ }
18
19
+ return arr
20
+}
0 commit comments