Skip to content

while-loop/go-walk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-walk




Random Walk package written in Go.

Given weights, receive callbacks for each direction.

Installation

$ go get github.com/while-loop/go-walk/walk

Usage

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)
}

Changelog

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

CHANGELOG.md

License

go-walk is licensed under the MIT license. See LICENSE for details.

Author

Anthony Alves

About

Random Walk package written in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages