rand

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Alpha = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"

Functions

func Float32

func Float32() float32

func Float64

func Float64() float64

func Int31n

func Int31n(n int32) int32

func Int63n

func Int63n(n int64) int64

func Intn

func Intn(n int) int

func NonWeightedChoice

func NonWeightedChoice(weightArray []int) int

NonWeightedChoice 根据权重随机,返回对应选项的索引,O(n). 权重大于等于0

func RandomChoice

func RandomChoice[T any](array []T, n int) []T

RandomChoice 随机选择数组中的元素

func RandomInt

func RandomInt(min, max int) int

RandomInt 根据区间产生随机数

func RandomInt32

func RandomInt32(min, max int32) int32

RandomInt32 根据区间产生随机数

func RandomInt64

func RandomInt64(min, max int64) int64

RandomInt64 根据区间产生随机数

func RandomString

func RandomString(l int) string

RandomString 随机字符串,包含大小写字母和数字

func Seed

func Seed(seedType SeedType) int64

Seed generates a seed based on the specified SeedType.

func Shuffle

func Shuffle[T any](array []T)

Shuffle 随机打乱数组

func WeightedChoice

func WeightedChoice(weightArray []int) int

WeightedChoice 根据权重随机,返回对应选项的索引,O(n)

Types

type Randomizer

type Randomizer struct {
	// contains filtered or unexported fields
}

func NewRandomizer

func NewRandomizer(seedType SeedType) *Randomizer

func (*Randomizer) Float32

func (r *Randomizer) Float32() float32

func (*Randomizer) Float64

func (r *Randomizer) Float64() float64

func (*Randomizer) Int

func (r *Randomizer) Int() int

func (*Randomizer) Int31

func (r *Randomizer) Int31() int32

func (*Randomizer) Int31n

func (r *Randomizer) Int31n(n int32) int32

func (*Randomizer) Int63

func (r *Randomizer) Int63() int64

func (*Randomizer) Int63n

func (r *Randomizer) Int63n(n int64) int64

func (*Randomizer) Intn

func (r *Randomizer) Intn(n int) int

func (*Randomizer) NonWeightedChoice

func (r *Randomizer) NonWeightedChoice(weightArray []int) int

NonWeightedChoice 根据权重随机,返回对应选项的索引,O(n). 权重大于等于0

func (*Randomizer) RandomString

func (r *Randomizer) RandomString(l int) string

RandomString 随机字符串,包含大小写字母和数字

func (*Randomizer) RangeFloat32

func (r *Randomizer) RangeFloat32(min, max float32) float32

RangeFloat32 根据区间产生随机数

func (*Randomizer) RangeFloat64

func (r *Randomizer) RangeFloat64(min, max float64) float64

RangeFloat64 根据区间产生随机数

func (*Randomizer) RangeInt

func (r *Randomizer) RangeInt(min, max int) int

RangeInt 根据区间产生随机数

func (*Randomizer) RangeInt32

func (r *Randomizer) RangeInt32(min, max int32) int32

RangeInt32 根据区间产生随机数

func (*Randomizer) RangeInt64

func (r *Randomizer) RangeInt64(min, max int64) int64

RangeInt64 根据区间产生随机数

func (*Randomizer) RangeUint

func (r *Randomizer) RangeUint(min, max uint) uint

RangeUint 根据区间产生随机数

func (*Randomizer) RangeUint32

func (r *Randomizer) RangeUint32(min, max uint32) uint32

RangeUint32 根据区间产生随机数

func (*Randomizer) RangeUint64

func (r *Randomizer) RangeUint64(min, max uint64) uint64

RangeUint64 根据区间产生随机数

func (*Randomizer) Uint32

func (r *Randomizer) Uint32() uint32

func (*Randomizer) Uint64

func (r *Randomizer) Uint64() uint64

func (*Randomizer) WeightedChoice

func (r *Randomizer) WeightedChoice(weightArray []int) int

WeightedChoice 根据权重随机,返回对应选项的索引,O(n)

type SeedType

type SeedType string
const (
	UnixNanoSeed     SeedType = "UnixNano"
	MapHashSeed      SeedType = "MapHash"
	CryptoRandSeed   SeedType = "CryptoRand"
	RandomStringSeed SeedType = "RandomString"
)

type Seeder

type Seeder struct {
	// contains filtered or unexported fields
}

func NewSeeder

func NewSeeder(seedType SeedType) *Seeder

func (*Seeder) CryptoRand

func (r *Seeder) CryptoRand() int64

func (*Seeder) MapHash

func (r *Seeder) MapHash() int64

func (*Seeder) RandomString

func (r *Seeder) RandomString() int64

func (*Seeder) Seed

func (r *Seeder) Seed() int64

func (*Seeder) UnixNano

func (r *Seeder) UnixNano() int64

Jump to

Keyboard shortcuts

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