You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
910 B
49 lines
910 B
4 months ago
|
package utils
|
||
|
|
||
|
import (
|
||
|
"math"
|
||
|
"math/rand"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func GetInvitation() string {
|
||
|
var bs = make([]byte, 6)
|
||
|
for i := 0; i < 6; i++ {
|
||
|
rand.Seed(time.Now().UnixNano())
|
||
|
flag := rand.Intn(2)
|
||
|
if flag == 1 {
|
||
|
bs[i] = byte(rand.Float64()*10 + 48)
|
||
|
} else {
|
||
|
bs[i] = byte(rand.Float64()*26 + 65)
|
||
|
}
|
||
|
}
|
||
|
return string(bs)
|
||
|
}
|
||
|
|
||
|
func GetInvitationLen(length int) string {
|
||
|
var bs = make([]byte, length)
|
||
|
for i := 0; i < length; i++ {
|
||
|
rand.Seed(time.Now().UnixNano())
|
||
|
flag := rand.Intn(3)
|
||
|
if flag == 1 {
|
||
|
bs[i] = byte(rand.Float64()*10 + 48)
|
||
|
} else if flag == 0 {
|
||
|
bs[i] = byte(rand.Float64()*26 + 65)
|
||
|
} else {
|
||
|
bs[i] = byte(rand.Float64()*26 + 97)
|
||
|
}
|
||
|
}
|
||
|
return string(bs)
|
||
|
}
|
||
|
|
||
|
func StringFloat64ToInt(s string) int {
|
||
|
f1, err := strconv.ParseFloat(s, 64)
|
||
|
if err != nil {
|
||
|
return 0
|
||
|
}
|
||
|
s1 := strconv.FormatFloat(math.Ceil(f1), 'f', -1, 64)
|
||
|
i, _ := strconv.Atoi(s1)
|
||
|
return i
|
||
|
}
|