Extract randomizer
This commit is contained in:
parent
a35e9d111a
commit
af5f43b03e
1 changed files with 9 additions and 5 deletions
14
main.go
14
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)
|
||||
|
|
Loading…
Reference in a new issue