Random Walk package written in Go.
Given weights, receive callbacks for each direction.
$ go get github.com/while-loop/go-walk/walk
package main
import (
"github.com/while-loop/go-walk/walk"
"fmt"
)
// Our walker that implements walk.Walker
type MyWalker struct {
// keep a counter for each direction
l, r, u, d int
}
func (w *MyWalker) Left() {
w.l++
}
func (w *MyWalker) Right() {
w.r++
}
func (w *MyWalker) Up() {
w.u++
}
func (w *MyWalker) Down() {
w.d++
}
func main() {
mw := &MyWalker{}
// Give custom weights to each direction
// Left, Right, Up, Down
w := walk.NewRandomWalk(10, 20, 30, 100, mw)
// perform a walk with 32 iterations
w.Walk(32)
// print the total amout of hits for each direction
fmt.Println("My Walker:", *mw)
}
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
go-walk is licensed under the MIT license. See LICENSE for details.
Anthony Alves