prox5/util.go

35 lines
687 B
Go
Raw Normal View History

2021-10-09 17:23:13 +00:00
package Prox5
2021-09-13 08:30:49 +00:00
import (
quiccmaffs "math/rand"
"time"
2021-09-13 08:30:49 +00:00
)
const (
grn = "\033[32m"
2021-09-24 19:07:56 +00:00
red = "\033[31m"
ylw = "\033[33m"
rst = "\033[0m"
)
2021-12-04 17:17:07 +00:00
// randStrChoice returns a random element from the given string slice.
2021-09-13 15:12:02 +00:00
func randStrChoice(choices []string) string {
2021-09-13 08:30:49 +00:00
strlen := len(choices)
n := uint32(0)
if strlen > 0 {
2021-09-13 15:12:02 +00:00
n = getRandomUint32() % uint32(strlen)
2021-09-13 08:30:49 +00:00
}
return choices[n]
}
2021-12-04 17:17:07 +00:00
// getRandomUint32 retrieves a random integer seeded by the current time.
2021-09-13 15:12:02 +00:00
func getRandomUint32() uint32 {
quiccmaffs.Seed(time.Now().UnixNano())
return quiccmaffs.Uint32()
}
func randSleep() {
quiccmaffs.Seed(time.Now().UnixNano())
2021-11-23 12:08:22 +00:00
time.Sleep(time.Duration(quiccmaffs.Intn(200)) * time.Millisecond)
2021-09-13 08:30:49 +00:00
}