Discover Packages
github.com/snail007/gmc
util
rand
package
Version:
v1.0.1
Opens a new window with list of versions in this module.
Published: Oct 25, 2025
License: MIT
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 5
Opens a new window with list of known importers.
README
README
¶
grand 包
简介
grand 包提供了随机数生成工具。
功能特性
随机字符串 :生成随机字符串
随机数字 :生成随机数字
UUID :生成 UUID
线程安全 :所有操作都是线程安全的
安装
go get github.com/snail007/gmc/util/rand
快速开始
package main
import (
"fmt"
"github.com/snail007/gmc/util/rand"
)
func main() {
r := grand.New()
// 随机字符串
str := grand.String(10)
fmt.Println("Random string:", str)
// 随机数字
num := r.Int()
fmt.Println("Random number:", num)
// 指定范围的随机数
rangeNum := r.IntRange(1, 100)
fmt.Println("Random in range:", rangeNum)
}
相关链接
Expand ▾
Collapse ▴
Documentation
¶
IntString returns the length random string only contains number and starts with no zero.
If length is 1, it returns 0-9 randomly, if length is 0, it returns empty.
New returns a new rand.Rand object of safe source.
String returns the length random string.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.