1
0
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:
o98k
2023-11-22 16:51:37 +08:00
committed by GitHub
parent 31c618c187
commit 3802c715c3
5 changed files with 109 additions and 0 deletions

View File

@@ -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
}