mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
feat: add RandFromGivenSlice function (#235)
* feat: add RandFromGivenSlice function * feat: add RandFromGivenSlice function
This commit is contained in:
@@ -43,6 +43,24 @@ func ExampleRandString() {
|
||||
// 6
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
}
|
||||
|
||||
func ExampleRandUpper() {
|
||||
pattern := `^[A-Z]+$`
|
||||
reg := regexp.MustCompile(pattern)
|
||||
|
||||
Reference in New Issue
Block a user