Fetch the repository succeeded.
/*
* @Name:
* @Descripttion:
* @Warning:
* @version:
* @Author: moo
* @Date: 2021-01-03 18:05:41
* @LastEditors: moo
* @LastEditTime: 2021-01-30 15:39:44
*/
package utils
import (
// "github.com/olongfen/gen-id"
"bytes"
"fmt"
"math/rand"
"time"
"github.com/srlemon/gen-id/generator"
)
/***
https://github.com/olongfen/gen-id
go get github.com/olongfen/gen-id@master
***/
const char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
func RandomName() string {
g := new(generator.GeneratorData)
return g.GeneratorName()
}
func RandomMobile() string {
g := new(generator.GeneratorData)
return g.GeneratorPhone()
}
func RandomInt(min int, max int) int {
if min >= max || max == 0 {
return max
}
time.Sleep(1)
rand.Seed(time.Now().UnixNano())
return min + rand.Intn(max-min)
}
func RandomTitle() string {
i := RandomInt(1, 99999)
s := fmt.Sprintf("标题[%05d]", i)
return s
}
func RandomSite() string {
i := RandomInt(1, 9999)
s := fmt.Sprintf("站点[%04d]", i)
return s
}
func RandomContent(size int) string {
a := make([]rune, size)
for i := range a {
a[i] = rune(RandomInt(19968, 40869))
}
return string(a)
}
func RandomString(size int) string {
rand.NewSource(time.Now().UnixNano()) // 产生随机种子
var s bytes.Buffer
for i := 0; i < size; i++ {
s.WriteByte(char[rand.Int63()%int64(len(char))])
}
return s.String()
}
func RandomTime() time.Time {
// min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
min := time.Date(2021, 1, 3, 0, 0, 0, 0, time.Local).Unix()
max := time.Date(2021, 1, 8, 0, 0, 0, 0, time.Local).Unix()
delta := max - min
sec := rand.Int63n(delta) + min
return time.Unix(sec, 0)
}
func RandFloat(min, max float64) float64 {
res := min + rand.Float64()*(max-min)
return res
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。