Skip to content

Random - 随机数生成

Random 提供随机数生成功能。

特性

  • 随机整数
  • 随机字符串
  • 随机选择
  • 随机打乱

安装

bash
go get github.com/go-zoox/random

快速开始

基本使用

go
package main

import (
    "fmt"
    "github.com/go-zoox/random"
)

func main() {
    // 生成随机整数
    num := random.Int(1, 100)
    fmt.Println("Random int:", num)
    
    // 生成随机字符串
    str := random.String(10)
    fmt.Println("Random string:", str)
    
    // 从数组中随机选择
    items := []string{"apple", "banana", "orange"}
    item := random.Choice(items)
    fmt.Println("Random choice:", item)
    
    // 打乱数组
    shuffled := random.Shuffle(items)
    fmt.Println("Shuffled:", shuffled)
}

更多信息

基于 VitePress 构建