diff --git a/main.go b/main.go index d451142..a672e8b 100644 --- a/main.go +++ b/main.go @@ -92,6 +92,14 @@ func visit(url string, authToken string) { 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() { err := godotenv.Load() @@ -112,11 +120,7 @@ func main() { authResult := login(basePath, username, password) subscriptions := getSubscriptions(basePath, authResult.Token) - // randomize subscription order - for i := range subscriptions { - j := rand.IntN(i + 1) - subscriptions[i], subscriptions[j] = subscriptions[j], subscriptions[i] - } + randomize(subscriptions) for i := range subscriptions { fmt.Println(subscriptions[i].Name)