mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-09 15:12:26 +08:00
feat: add RandSliceFromGivenSlice function (#236)
This commit is contained in:
@@ -47,18 +47,15 @@ func ExampleRandFromGivenSlice() {
|
||||
goods := []string{"apple", "banana", "cherry", "elderberry", "fig", "grape", "honeydew", "kiwi", "lemon",
|
||||
"mango", "nectarine", "orange"}
|
||||
|
||||
isInGoods := false
|
||||
result := RandFromGivenSlice(goods)
|
||||
for _, good := range goods {
|
||||
if good == result {
|
||||
isInGoods = true
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Println(isInGoods)
|
||||
fmt.Println(result)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// true
|
||||
func ExampleRandSliceFromGivenSlice() {
|
||||
goods := []string{"apple", "banana", "cherry", "elderberry", "fig", "grape", "honeydew", "kiwi", "lemon",
|
||||
"mango", "nectarine", "orange"}
|
||||
chosen3goods := RandSliceFromGivenSlice(goods, 3, false)
|
||||
fmt.Println(chosen3goods)
|
||||
}
|
||||
|
||||
func ExampleRandUpper() {
|
||||
|
||||
Reference in New Issue
Block a user