Skip to content

Commit

Permalink
Add Cohen's algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nemuelw committed Sep 23, 2023
1 parent b9029c3 commit 479adf7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion shuffler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ func DurstenfeldShuffle[T any](arr []T) {
}
}


func CohensShuffle[T any](arr []T) {
rand.Seed(time.Now().UnixNano())
n := len(arr)
for i := 0; i < n; i++ {
j := rand.Intn(n)
arr[i], arr[j] = arr[j], arr[i]
}
}

0 comments on commit 479adf7

Please sign in to comment.