grand

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 5 Imported by: 5

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)
}

相关链接

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntString

func IntString(length int) string

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.

func New

func New() *rand.Rand

New returns a new rand.Rand object of safe source.

func String

func String(length int) string

String returns the length random string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL