|
|
@@ -1,7 +1,7 @@ |
|
|
|
package util |
|
|
|
|
|
|
|
import ( |
|
|
|
// "fmt" |
|
|
|
"fmt" |
|
|
|
"math/rand" |
|
|
|
"time" |
|
|
|
) |
|
|
@@ -13,6 +13,10 @@ import ( |
|
|
|
// return ary[rand.Intn(l)] |
|
|
|
// } |
|
|
|
|
|
|
|
func Debug(msg ...interface{}) { |
|
|
|
fmt.Println(msg) |
|
|
|
} |
|
|
|
|
|
|
|
func ChoiceInt(ary []int) int { |
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
l := len(ary) |
|
|
@@ -26,3 +30,28 @@ func ChoiceStr(ary []string) string { |
|
|
|
// fmt.Printf("Selected %s (element %d)\n", ary[r], r) |
|
|
|
return ary[r] |
|
|
|
} |
|
|
|
|
|
|
|
func ChoiceMap(ary map[string]int) (string, int) { |
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
l := len(ary) |
|
|
|
// fmt.Println(l) |
|
|
|
key, val, rot := "", 0, 0 |
|
|
|
for key == "" { |
|
|
|
Debug(rot, key, val) |
|
|
|
for k, v := range ary { |
|
|
|
Debug(k, v) |
|
|
|
// Debug(rot) |
|
|
|
r := 0 |
|
|
|
if rot < 3 { |
|
|
|
r = rand.Intn(l) |
|
|
|
} |
|
|
|
if r == 0 { |
|
|
|
key, val = k, v |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
rot++ |
|
|
|
// fmt.Println(key, val) |
|
|
|
} |
|
|
|
return key, val |
|
|
|
} |