17 Star 44 Fork 12

hanguofeng / gocaptcha

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
randhelper.go 743 Bytes
一键复制 编辑 原始数据 按行查看 历史
hanguofeng 提交于 2013-09-08 01:06 . init
// Copyright 2013 hanguofeng. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gocaptcha
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// rnd returns a non-crypto pseudorandom int in range [from, to].
func rnd(from, to int) int {
return rand.Intn(to+1-from) + from
}
// rndf returns a non-crypto pseudorandom float64 in range [from, to].
func rndf(from, to float64) float64 {
return (to-from)*rand.Float64() + from
}
func randStr(length int) string {
rst := ""
charset := "abcdefghijklmnopqrstuvwxyz1234567890"
for i := 0; i < length; i++ {
rst = rst + string(charset[rnd(0, len(charset)-1)])
}
return rst
}
1
https://gitee.com/hanguofeng/gocaptcha.git
git@gitee.com:hanguofeng/gocaptcha.git
hanguofeng
gocaptcha
gocaptcha
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891