https://github.com/issue9/rands
随机字符串产生函数
https://github.com/issue9/rands
rand random random-string
Last synced: 2 months ago
JSON representation
随机字符串产生函数
- Host: GitHub
- URL: https://github.com/issue9/rands
- Owner: issue9
- License: mit
- Created: 2016-01-04T13:43:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2025-02-12T18:43:25.000Z (about 1 year ago)
- Last Synced: 2026-01-12T05:45:38.768Z (3 months ago)
- Topics: rand, random, random-string
- Language: Go
- Homepage: https://pkg.go.dev/github.com/issue9/rands/v3
- Size: 71.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
rands
[](https://actions-badge.atrox.dev/issue9/rands/goto?ref=master)
[](https://opensource.org/licenses/MIT)
[](https://codecov.io/gh/issue9/rands)
[](https://pkg.go.dev/github.com/issue9/rands/v3)
======
rands 为一个随机字符串生成工具。
*从 v3 开始只支持 go1.22 以之后的版本*
```go
// 拿 [8,10) 数量的 rune,每个汉字都是完整的。
str := rands.String(8, 10, []rune("rands 为一个随机字符串生成工具"))
// 拿 [8,10) 数量的 byte,汉字可能会被截断。
str := rands.String(8, 10, []byte("rands 为一个随机字符串生成工具"))
// 生成一个带缓存功能的随机字符串生成器
r, err := rands.New(time.Now().Unix(), 100, 5, 7, []byte("asdfghijklmn"))
ctx,cancel := context.WithCancel(context.Background())
go r.Serve(ctx)
defer cancel()
str1 := r.String()
str2 := r.String()
```
安装
----
```shell
go get github.com/issue9/rands/v3
```
版权
----
本项目采用 [MIT](https://opensource.org/licenses/MIT) 开源授权许可证,完整的授权说明可在 [LICENSE](LICENSE) 文件中找到。