Spaces:
Configuration error
Configuration error
File size: 577 Bytes
6c0b3e3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | package utils
import "math/rand"
// ShuffleWithKey mengacak slice dengan menggunakan integer key sebagai seed
// untuk memastikan hasil acak yang konsisten untuk key yang sama
func ShuffleWithKey[T any](slice []T, key int64) []T {
// Buat salinan slice untuk menghindari modifikasi original
shuffled := make([]T, len(slice))
copy(shuffled, slice)
// Buat random source dengan seed dari key
r := rand.New(rand.NewSource(key))
// Lakukan shuffling
r.Shuffle(len(shuffled), func(i, j int) {
shuffled[i], shuffled[j] = shuffled[j], shuffled[i]
})
return shuffled
}
|