From f375e7a85a9c74a6b77438139bee4750c2aa00d4 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Fri, 8 Aug 2025 13:48:29 -0400 Subject: Random affected services Incidents are not every 10 seconds --- internal/api/utilities.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'internal/api/utilities.go') diff --git a/internal/api/utilities.go b/internal/api/utilities.go index 508e341..4a816fc 100644 --- a/internal/api/utilities.go +++ b/internal/api/utilities.go @@ -72,3 +72,27 @@ func addRotLog(logs *[LogLength]string, last *int, parser chan string, value str } } } + +func randomSelect[T any](src []T, n int) []T { + if n <= 0 || len(src) == 0 { + return nil + } + if n >= len(src) { + // Return a copy of the whole slice + cpy := make([]T, len(src)) + copy(cpy, src) + return cpy + } + + // Make a copy so we don't modify the original slice + tmp := make([]T, len(src)) + copy(tmp, src) + + // Shuffle the copy in‑place + rand.Shuffle(len(tmp), func(i, j int) { + tmp[i], tmp[j] = tmp[j], tmp[i] + }) + + // Return the first n elements of the shuffled slice + return tmp[:n] +} -- cgit