mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-09 07:02:29 +08:00
[feature]<slice>: support random item (#146)
Signed-off-by: o98k-ok <hggend@gmail.com>
This commit is contained in:
@@ -1063,3 +1063,14 @@ func ExamplePartition() {
|
||||
// [[2 4] [1 3 5]]
|
||||
// [[1 2] [3 4] [5]]
|
||||
}
|
||||
|
||||
func ExampleRandom() {
|
||||
nums := []int{1, 2, 3, 4, 5}
|
||||
|
||||
val, idx := Random(nums)
|
||||
if idx >= 0 && idx < len(nums) && Contain(nums, val) {
|
||||
fmt.Println("okk")
|
||||
}
|
||||
// Output:
|
||||
// okk
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user