Spaces:
Configuration error
Configuration error
| 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 | |
| } | |