1
0
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:
残念
2024-08-15 15:20:36 +08:00
committed by GitHub
parent 7b4e060f85
commit c2a5335bc6
5 changed files with 134 additions and 10 deletions

View File

@@ -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() {