Extract randomizer

This commit is contained in:
GHOSCHT 2024-12-28 21:01:37 +01:00
parent a35e9d111a
commit af5f43b03e
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82

14
main.go
View file

@ -92,6 +92,14 @@ func visit(url string, authToken string) {
fmt.Println(res.Status) fmt.Println(res.Status)
} }
// Randomize subscription order
func randomize[S any](slice []S) {
for i := range slice {
j := rand.IntN(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
}
func main() { func main() {
err := godotenv.Load() err := godotenv.Load()
@ -112,11 +120,7 @@ func main() {
authResult := login(basePath, username, password) authResult := login(basePath, username, password)
subscriptions := getSubscriptions(basePath, authResult.Token) subscriptions := getSubscriptions(basePath, authResult.Token)
// randomize subscription order randomize(subscriptions)
for i := range subscriptions {
j := rand.IntN(i + 1)
subscriptions[i], subscriptions[j] = subscriptions[j], subscriptions[i]
}
for i := range subscriptions { for i := range subscriptions {
fmt.Println(subscriptions[i].Name) fmt.Println(subscriptions[i].Name)