Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
15 lines
202 B
Go
15 lines
202 B
Go
package testutil
|
|
|
|
import (
|
|
"math/rand"
|
|
)
|
|
|
|
func RandSliceElem[E any](r *rand.Rand, elems []E) (E, bool) {
|
|
if len(elems) == 0 {
|
|
var e E
|
|
return e, false
|
|
}
|
|
|
|
return elems[r.Intn(len(elems))], true
|
|
}
|