Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 889 Bytes

README.md

File metadata and controls

23 lines (15 loc) · 889 Bytes

Crazy randtest

GoDoc CircleCI Codecov

randtest controls the math/rand.Rand behavior from the Source for testing purpose.

type Behavior struct{}

func (b *Behavior) Intn(n int) int {
	return n / 2
}

func main() {
	source := randtest.NewSource(&Behavior{})
	r := rand.New(source)

	fmt.Println(r.Intn(10)) // Always 5.
}

This is experimental package. It can be broken by updating Go because the logic is highly depends on undocumented behavior of math/rand package. Only tested on Go1.11.