commit
c5280523ca
@ -0,0 +1,17 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: clone
|
||||
|
||||
steps:
|
||||
- name: Test
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- go test -v ./...
|
||||
- name: Benchmark
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- go test -bench=. -benchmem
|
@ -0,0 +1,9 @@
|
||||
.env
|
||||
.git
|
||||
.svn
|
||||
.idea
|
||||
.vscode
|
||||
*.log
|
||||
goinit.sh
|
||||
gomod.sh
|
||||
/vendor/
|
@ -0,0 +1,50 @@
|
||||
package gorandom
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
const numbers string = "0123456789"
|
||||
const letters string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
const specials = "~!@#$%^*()_+-=[]{}|;:,./<>?"
|
||||
const alphanumerics string = letters + numbers
|
||||
const ascii string = alphanumerics + specials
|
||||
|
||||
func random[T int | int64](n T, chars string) string {
|
||||
if n <= 0 {
|
||||
return ""
|
||||
}
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
bytes := make([]byte, n, n)
|
||||
l := len(chars)
|
||||
var i T = 0
|
||||
for {
|
||||
if i >= n {
|
||||
break
|
||||
}
|
||||
bytes[i] = chars[r.Intn(l)]
|
||||
i++
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
// Alphanumeric 随机字母数字
|
||||
func Alphanumeric[T int | int64](n T) string {
|
||||
return random(n, alphanumerics)
|
||||
}
|
||||
|
||||
// Alphabetic 随机字母
|
||||
func Alphabetic[T int | int64](n T) string {
|
||||
return random(n, letters)
|
||||
}
|
||||
|
||||
// Numeric 随机数字
|
||||
func Numeric[T int | int64](n T) string {
|
||||
return random(n, numbers)
|
||||
}
|
||||
|
||||
// Ascii 随机ASCII
|
||||
func Ascii[T int | int64](n T) string {
|
||||
return random(n, ascii)
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package gorandom
|
||||
|
||||
const Version = "1.0.0"
|
@ -0,0 +1,7 @@
|
||||
package gorandom
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
t.Log(Version)
|
||||
}
|
Loading…
Reference in new issue