crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoElementItem = errors.New("crypto/rand: no element item to pick")

ErrNoElementItem 列表裡沒有任何可用對象

Functions

func RandBytes

func RandBytes(n int) ([]byte, error)

RandBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func RandInt

func RandInt(max int64) (int64, error)

RandInt returns an int64 securely generated random int64. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func RandString

func RandString(s int) (string, error)

RandString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

type IntsRandPicker

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

IntsRandPicker 隨機選取一個int值,直到全部int取完為止

func NewIntsRandPicker

func NewIntsRandPicker(min, max int) *IntsRandPicker

NewIntsRandPicker 生成int隨機

func NewIntsRandPickerItems

func NewIntsRandPickerItems(items ...int) *IntsRandPicker

NewIntsRandPickerItems 生成int隨機

func (*IntsRandPicker) HasNext

func (irp *IntsRandPicker) HasNext() bool

HasNext 是否還有下一個元素

func (*IntsRandPicker) Next

func (irp *IntsRandPicker) Next() (int, error)

Next 隨機挑選下一個值,並且從待選數組裡面移除,非線程安全

func (*IntsRandPicker) Rand

func (irp *IntsRandPicker) Rand() (int, error)

Rand 隨機挑選下一個值,但是不從數組裡移除,非線程安全

type RandPicker

type RandPicker interface {
	//Add 增加一個選項
	Add(items ...interface{})

	//HasNext 是否還有下一個對象
	HasNext() bool

	//隨機挑選下一個值,並且從待選數組裡面移除
	Next() (interface{}, error)

	//隨機挑選一個值,但是不做移除
	Rand() (interface{}, error)
}

RandPicker 數組隨機項抽取器

func NewRandPicker

func NewRandPicker(max int) RandPicker

NewRandPicker 創建數組隨機抽取器實例

Jump to

Keyboard shortcuts

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