mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-02 05:57:09 -05:00
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
19 lines
476 B
Go
19 lines
476 B
Go
// Package arrutil provides some util functions for array, slice
|
|
package arrutil
|
|
|
|
import (
|
|
"github.com/gookit/goutil/mathutil"
|
|
)
|
|
|
|
// GetRandomOne get random element from an array/slice
|
|
func GetRandomOne[T any](arr []T) T { return RandomOne(arr) }
|
|
|
|
// RandomOne get random element from an array/slice
|
|
func RandomOne[T any](arr []T) T {
|
|
if ln := len(arr); ln > 0 {
|
|
i := mathutil.RandomInt(0, len(arr))
|
|
return arr[i]
|
|
}
|
|
panic("cannot get value from nil or empty slice")
|
|
}
|