Skip to content

An implemention of randomized weighed array in go

Notifications You must be signed in to change notification settings

artback/weightedarray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

weightedarrays Optimized for simplicity of use.

To use this library you need to implement the Value interface.

type Fruit struct {  
 Name   string 
 Weight float64 
 Draws  int
}
   
func (f Fruit) GetWeight() float64 {  
 return f.Weight
 }  
 
items := weightedarray.Values{  
 &Fruit{Name: "Banana", Weight: 1}, 
 &Fruit{Name: "Lemon", Weight: 2}, 
 &Fruit{Name: "Apple", Weight: 4}, 
 &Fruit{Name: "Mellon", Weight: 8}, 
 &Fruit{Name: "Orange", Weight: 10}, 
 &Fruit{Name: "Pineapple", Weight: 7},
}

To retrieve a weighted value you call

 value =: items.Random()

About

An implemention of randomized weighed array in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages