package wave import ( "math/rand/v2" "sort" ) func shuffle[T any](in []T) []T { out := append([]T(nil), in...) rand.Shuffle(len(out), func(i, j int) { out[i], out[j] = out[j], out[i] }) return out } func stableSort[T any](s []T, less func(a, b T) bool) { sort.SliceStable(s, func(i, j int) bool { return less(s[i], s[j]) }) }