Spaces:
Configuration error
Configuration error
Download space/utils/shuffle.go from lifedebugger/api-qobiltu-dev: direct link, hf CLI and curl.
- Browser
- Download file 577 Bytes
-
https://huggingface.co/spaces/lifedebugger/api-qobiltu-dev/resolve/main/space/utils/shuffle.go
- Command line
-
hf download hf://spaces/lifedebugger/api-qobiltu-dev/space/utils/shuffle.go
-
curl -L -o shuffle.go https://huggingface.co/spaces/lifedebugger/api-qobiltu-dev/resolve/main/space/utils/shuffle.go
577 Bytes
| 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 | |
| } | |