lottery

package module
v0.0.0-...-ac56dd2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 5 Imported by: 0

README

lottery

Install

go get -u github.com/syhlion/lottery

Usaged

type Item struct {
    Name string
    Prob int
}
func (i Item) Prob() int{
    return i.Prob
}
func main(){
    lott := New()
    items :=[]lottery.Item{
        Item{Name:"a",Prob:5},
        Item{Name:"b",Prob:20},
        Item{Name:"c",Prob:10},
        Item{Name:"d",Prob:10},
        Item{Name:"e",Prob:50},
        Item{Name:"f",Prob:5},
    }

    //mulit rand
    idx:=lottery.Pick(items ...)
    switch i:= items[idx].(type){
        case Item:
         fmt.Println(i.Name)
    }

    //shuffle rand
    shuffleItems := lott.Shuffle(items ...)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	Prob() int
}

type ItemSort

type ItemSort []Item

func (ItemSort) Len

func (is ItemSort) Len() int

func (ItemSort) Less

func (is ItemSort) Less(i, j int) bool

func (ItemSort) Swap

func (is ItemSort) Swap(i, j int)

type Lottery

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

func New

func New() *Lottery

func (*Lottery) Pick

func (l *Lottery) Pick(items ...Item) int

func (*Lottery) Shuffle

func (l *Lottery) Shuffle(items ...Item) (dest []Item)

Source Files

  • lottery.go

Jump to

Keyboard shortcuts

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