feat: add RandFromGivenSlice function (#235)

* feat: add RandFromGivenSlice function

* feat: add RandFromGivenSlice function
This commit is contained in:
残念 authored and GitHub committed 2024-08-14 19:36:12 +08:00
1 parent a360372aa9
commit 7b4e060f85
5 files changed
+105

No files matched your search

+18
View File
@@ -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)