Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomNOfSet ¶
func RandomNOfSet(set interface{}, n int) []interface{}
RandomOfSet returns a slice of random values from a set. If the input is a map, the return value is a slice of random keys from the map. If the input is not a container type, it is returned as a single element []interface{} containing only the input.
This function operates on generics, and uses reflection in the background. The return value must be copy-casted back into the original container type by the caller, eg.:
n := 20 arr := []int{1,2,3,4,5} result := make([]int, n) for i, d := range RandomNOfSet(arr, n).([]interface{}) { result[i] := d.(int) }
func RandomOfSet ¶
func RandomOfSet(set interface{}) interface{}
RandomOfSet returns a random value from a set. If the input is a map, the return value is a random key from the map. If the input is not a container type, the input is returned.
This function operates on generics, and uses reflection in the background. The return value must be casted back into the original type by the caller, eg.:
arr := []int{1,2,3,4,5} x := RandomOfSet(arr).(int)
Types ¶
This section is empty.