From 3a815dcf23323d2f1d0b830c5cb5037d09156677 Mon Sep 17 00:00:00 2001 From: Simon Garrelou Date: Sat, 10 Dec 2022 22:35:46 +0100 Subject: Add shuffle + fix deadlocks --- src/app.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/app.go') diff --git a/src/app.go b/src/app.go index ee1b342..b998a50 100644 --- a/src/app.go +++ b/src/app.go @@ -2,7 +2,9 @@ package src import ( "fmt" + "math/rand" "os" + "time" "git.sixfoisneuf.fr/termsonic/music" "github.com/delucks/go-subsonic" @@ -158,3 +160,13 @@ func (a *app) switchToPage(name string) { a.updateFooter() } + +func randomize(t []*subsonic.Child) []*subsonic.Child { + t2 := make([]*subsonic.Child, len(t)) + copy(t2, t) + + rand.Seed(time.Now().UnixNano()) + rand.Shuffle(len(t2), func(i, j int) { t2[i], t2[j] = t2[j], t2[i] }) + + return t2 +} -- cgit v1.2.3